我在运行Unity应用程序时遇到类错误。我有一个我写的编译为aar的本机代码库。我刚刚更新了一些代码以支持Android 8上的本地通知,并且我使用了Android X“Worker”类。我的编译很好,但我想我错过了一个包含在Unity项目中的库。我应该添加哪个库?
错误是
06-05 10:57:52.970: E/AndroidRuntime(21759): FATAL EXCEPTION: IntentService[com.help.stressfree.localnotifications.NotificationService]
06-05 10:57:52.970: E/AndroidRuntime(21759): Process: com.help.stressfree, PID: 21759
06-05 10:57:52.970: E/AndroidRuntime(21759): java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/work/Data$Builder;
06-05 10:57:52.970: E/AndroidRuntime(21759): at com.help.stressfree.localnotifications.NotificationService.ScheduleNotification(NotificationService.java:99)
06-05 10:57:52.970: E/AndroidRuntime(21759): at com.help.stressfree.localnotifications.NotificationService.onHandleIntent(NotificationService.java:82)
06-05 10:57:52.970: E/AndroidRuntime(21759): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:68)
06-05 10:57:52.970: E/AndroidRuntime(21759): at android.os.Handler.dispatchMessage(Handler.java:105)
06-05 10:57:52.970: E/AndroidRuntime(21759): at android.os.Looper.loop(Looper.java:164)
06-05 10:57:52.970: E/AndroidRuntime(21759): at android.os.HandlerThread.run(HandlerThread.java:65)
06-05 10:57:52.970: E/AndroidRuntime(21759): Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.work.Data$Builder" on path: DexPathList[[zip file "/data/app/com.help.stressfree-FN_ED1fyI9LY4tcsB1RWqQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.help.stressfree-FN_ED1fyI9LY4tcsB1RWqQ==/lib/arm, /data/app/com.help.stressfree-FN_ED1fyI9LY4tcsB1RWqQ==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
06-05 10:57:52.970: E/AndroidRuntime(21759): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
06-05 10:57:52.970: E/AndroidRuntime(21759): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
06-05 10:57:52.970: E/AndroidRuntime(21759): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
这是aar库的gradle文件,如果相关的话:
//indicates that this is a library
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
sourceSets {
main {
//Path to your source code
java {
srcDir 'src/main/java'
}
}
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compileOnly fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
testImplementation 'junit:junit:4.12'
compileOnly files('libs/classes.jar', 'libs/libmessaging_unity_player_activity.jar')
def work_version = "1.0.0-alpha02"
implementation "android.arch.work:work-runtime:$work_version" // use -ktx for Kotlin
}
//task to delete the old jar
task deleteOldJar(type: Delete) {
delete 'default/AndroidPlugin.jar'
}
//task to export contents as jar
task exportJar(type: Copy) {
from('build/intermediates/bundles/default/')
into('libs/jar')
include('classes.jar')
///Rename the jar
rename('classes.jar', 'AndroidPlugin.jar')
}
exportJar.dependsOn(deleteOldJar, build)
//task to delete the old jar
task deleteOldAAR(type: Delete) {
}
//task to export contents as jar
task exportAAR(type: Copy) {
from('build/outputs/aar/')
into('libs/aars')
include('app-debug.aar')
///Rename the jar
rename('app-debug.aar', 'AndroidPlugin.aar')
}
exportAAR.dependsOn(deleteOldAAR, build)
答案 0 :(得分:0)
正如我所看到的,您已将库添加为aar
文件,但该文件本身并不包含库依赖关系。如果您使用的是Gradle,则还应添加库依赖关系,在这种情况下为android-workmanager
。
因此,在这些情况下,请执行以下解决方案:
在 Gradle 系统上,带有 aar 文件。
build.gradle
文件中)。在 Gradle 系统上,将库作为 Maven 工件: