我们有一个 android 蓝牙 java 插件,它具有适合我们项目的特定功能。该插件可以正常工作,但我们无法满足权限请求(在测试期间,我们手动启用权限)。
下面是我们在Android Studio项目中的build.gradle:
plugins {
id 'com.android.library'
}
android {
compileSdk 33
namespace 'com.{ourcompanyremovedforstackoverflow}.{projectremovedforstackoverflow}'
defaultConfig {
minSdk 31
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
ndkVersion '25.2.9519653'
}
dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'androidx.core:core:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
android.useAndroidX=true android.enableJetifier=true
都在 gradle.properties 中启用,并且我们使用的是 Java 11。所有其他功能都可以工作,尽管我们必须直接通过
implementation files('libs/gson-2.10.1.jar')
实现 gson 插件,因为这也失败了。对 androidx.core 和 androidx.appcompat 执行相同操作并没有解决问题。
根据 Unity 文档,对 Unity 2022.3 使用 gradle 7.1.2。
有人知道这里可能配置错误吗?
我们尝试更改插件版本,在 Unity 中设置手动 build.gradle 文件,并确保 proguard 不会剔除任何依赖项。
我想通了。如果有人遇到同样的问题,您实际上也需要更新 Unity 项目上的 mainGradle。插件没有任何问题,但是 Unity 中的 gradle 构建阶段根本不知道该怎么办。
更新了 Unity 项目 mainTemplate.gradle 中的依赖项(请务必在构建设置中勾选自定义 MainGradleTemplate)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def core_version = "1.10.0"
def appcompat_version = "1.6.0"
implementation 'com.google.code.gson:gson:2.10.1'
implementation "androidx.core:core:$core_version"
DEPS}
此外,请务必勾选自定义 Gradle 属性模板并添加
android.useAndroidX=true android.enableJetifier=true
还有旗帜。
我想下一步是让插件自动将其注入到构建 gradle 中以方便起见。