1 year ago
#305637
ArtemiZ Studio
Failed resolution of Landroidx / ActivityCompat;
I'm trying to make a java library for my Unity game. In this case I want get permission from Android API. However, I get an error:
AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/ActivityCompat;
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/ActivityCompat;
at com.company.test.PermissionsManager.requestPermissions(PermissionsManager.java:44)
at com.company.test.PermissionsManager.requestPermissions(PermissionsManager.java:34)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.ActivityCompat" on path: DexPathList[[zip file "/data/app/~~4Ois8qA39auK0A7jeoofDQ==/com.company.test-P2aLy8E-8yfCZc65VObuTQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~4Ois8qA39auK0A7jeoof
Here is build.gradle
:
plugins {
id 'com.android.library'
}
android {
compileSdk 31
defaultConfig {
minSdk 28
targetSdk 31
}
buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation "androidx.core:core-ktx:+"
compileOnly files('./libs/classes.jar') //Unity classes
}
PermissionManager:
package com.company.test;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
public class PermissionsManager extends ContextHolder {
public PermissionsManager(Context paramContext) {
super(paramContext);
}
public static boolean isPermissionsGranted(String paramString, Context paramContext) {
return !(Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(paramContext, paramString) != 0);
}
public void addPermissionRequestListener(PermissionRequestListener paramPermissionRequestListener) {
((MainActivity)this.context).addPermissionRequestListener(paramPermissionRequestListener);
}
public boolean isPermissionGranted(String paramString) {
return isPermissionsGranted(paramString, this.context);
}
public void removePermissionRequestListener(PermissionRequestListener paramPermissionRequestListener) {
((MainActivity)this.context).removePermissionRequestListener(paramPermissionRequestListener);
}
public void requestPermissions(String[] paramArrayOfString) {
requestPermissions(paramArrayOfString, null);
}
public void requestPermissions(String[] paramArrayOfString, PermissionRequestListener paramPermissionRequestListener) {
MainActivity mainActivity = (MainActivity)this.context;
if (paramPermissionRequestListener != null) {
int j = paramArrayOfString.length;
for (int i = 0; i < j; i++)
mainActivity.addPermissionRequestCallback(paramArrayOfString[i], paramPermissionRequestListener);
}
ActivityCompat.requestPermissions((Activity)mainActivity, paramArrayOfString, 0);
}
}
I think the problem may be somewhere in the build.gradle
, but from my poor experience with android libraries, I do not see any errors
android
android-studio
unity-game-engine
gradle
androidx
0 Answers
Your Answer