当我运行我的 Unity 应用程序时,我遇到了丢失的类错误。我有一个编写为 aar 的本机代码库。我刚刚更新了一些代码以支持 Android 8 上的本地通知,并且我使用了 Android X“Worker”类。我的 aar 编译得很好,但我想我缺少一个要包含在 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)