android - Untiy android插件类未找到异常
问题描述
我正在为统一编写一个 android 插件,以便能够检查是否为游戏启用了通知。我有一个带有检查通知是否启用的方法的 java 类。当我构建插件和统一的 .apk 时,一切正常。但安装后,调用方法时出现以下异常:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/NotificationManagerCompat;
Java 类
package com.example.plugin;
import android.app.Activity;
import androidx.core.app.NotificationManagerCompat;
public class NotificationPlugin {
public static boolean areNotificationEnabled(Activity unityActivity) {
return NotificationManagerCompat.from(unityActivity).areNotificationsEnabled();
}
}
buld.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
gradle.properties
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true
还没有在其他地方找到解决方案。预先感谢。这可能是我想念的一个超级简单的修复。
更新
android.enableJetifier
统一设置的自定义 gradle.propertiesandroid.useAndroidX
设置为 true- Jetifier 统一启用
- 插件的 gradle.build 文件的依赖项中添加了 Androidx.Core 库
以上都没有解决问题
解决方案
正如 Hamid Yusifli 在他的回答中建议的那样,需要启用自定义 gradle 构建模板(项目设置>播放器>发布设置>自定义主 Gralde 模板),并且需要添加库的依赖项(implementation 'androidx.core:core:1.5.0'
在我的情况下)。这解决了这个问题。
解决方案
因此,在您的情况下,似乎统一忽略了您的库 gradle 依赖项,这可能发生的原因有很多。要强制统一包含缺少的依赖项,您必须提供自定义Gradle 构建模板并在该文件中添加您的依赖项。
推荐阅读
- r - 混合来自不同图层的颜色
- postgresql - CKan toolkit.get_action 函数在按 package_count 排序时给出空列表
- jestjs - 是否可以使用 Puppeteer 拍摄独立于设备的屏幕截图?
- verilog - RTL Verilog (FPGA) 可综合代码的时钟转换
- ios - iOS 托管应用程序配置和设备注册
- javascript - JS和PHP的问题
- javascript - 使用下拉选择选项按日期对列表进行排序
- django - django 子组最大值的总和
- angular - Angular:组合应用程序,但作为单独的项目开发
- wordpress - 按元字段订购 WooCommerce 产品