原因:org.gradle.api.internal.plugins.PluginApplicationException:无法应用插件 [id 'dexguard']
Posted
技术标签:
【中文标题】原因:org.gradle.api.internal.plugins.PluginApplicationException:无法应用插件 [id \'dexguard\']【英文标题】:Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'dexguard']原因:org.gradle.api.internal.plugins.PluginApplicationException:无法应用插件 [id 'dexguard'] 【发布时间】:2021-06-26 08:56:57 【问题描述】:我正在 android 项目中将 Dexguard 从 v8 升级到最新版本 9.0.17。到目前为止,一切正常,但现在我需要你的帮助。
按照教程如何在 Android Studio 中从 v8 升级到 v9 并重建项目,我收到错误:Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ' dexguard']
我不确定发生了什么。我尝试了许多组合来修复它并使其工作,但没有成功。她是我的文件: build.gradle ->
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
repositories
maven
url 'http://developer.huawei.com/repo/'
google() // For Android plugin
jcenter() // For anything else
flatDir
dirs 'app/libs/dexguard'
dependencies
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.3.3'
//classpath 'io.fabric.tools:gradle:1.31.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
//classpath 'com.guardsquare.dexguard:dexguard-gradle-plugin:'
classpath 'com.guardsquare:dexguard-gradle-plugin:9.0.17'
//HUAWEI
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
google()
jcenter()
maven url "https://maven.google.com"
maven url "https://jitpack.io"
maven url 'http://developer.huawei.com/repo/'
flatDir
dirs 'libs'
task clean(type: Delete)
delete rootProject.buildDir
和 build.gradle(app) 文件 -> :
apply plugin: 'com.android.application'
//apply plugin: 'com.huawei.agconnect'
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Huawei"))
apply plugin: 'com.huawei.agconnect'
println 'Huawei plugins loading'
else
println 'Google plugins loading'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'dexguard'
android
// buildToolsVersion '27.0.3'
defaultConfig
compileSdkVersion 29
applicationId "com.xxxx.project"
minSdkVersion 19
targetSdkVersion 29
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
versionCode = 281
versionName = "2.26"
archivesBaseName = "AppName v$versionName"
ndk
abiFilters "armeabi-v7a", "arm64-v8a"
externalNativeBuild
cmake
arguments "-DANDROID_STL=c++_static"
cppFlags "-std=c++11"
cppFlags "-fexceptions"
dexOptions
javaMaxHeapSize "2g"
// You should remove the proguardFile configurations and set minifyEnabled and shrinkResources to false.
buildTypes
debug
/*proguardFile getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-project.txt'*/
minifyEnabled false
shrinkResources false
release
/*proguardFile getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-project.txt'*/
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Google"))
println 'Google crashlytics loading for release'
firebaseCrashlytics.mappingFileUploadEnabled true
firebaseCrashlytics
nativeSymbolUploadEnabled true
minifyEnabled false
shrinkResources false
compileOptions
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
externalNativeBuild
cmake
path "CMakeLists.txt"
flavorDimensions "appID", "provider"
productFlavors
create("appTest")
applicationId = "com.xxxx.project"
dimension "appID"
buildConfigField "boolean", "IS_PRODUCTION", "false"
buildConfigField "boolean", "PRINT_LOGS", "true"
buildConfigField "boolean", "SAVE_LOGS", "false"
buildConfigField "boolean", "IS_USER_TESTER", "false"
buildConfigField "boolean", "IS_GEAR_ENABLED", "true"
create("appProduction")
applicationId = "com.xxxx.project"
dimension "appID"
signingConfig = null
buildConfigField "boolean", "IS_PRODUCTION", "true"
buildConfigField "boolean", "PRINT_LOGS", "false"
buildConfigField "boolean", "SAVE_LOGS", "false"
buildConfigField "boolean", "IS_USER_TESTER", "false"
buildConfigField "boolean", "IS_GEAR_ENABLED", "true"
huawei
dimension "provider"
google
dimension "provider"
sourceSets
main
jniLibs.srcDirs = ['src/main/cpp']
// You can specify your DexGuard configurations in a new dexguard block:
dexguard
jvmArgs '-Xmx1536m'
//path = 'app/libs/dexguard'
configurations
debug
defaultConfiguration 'dexguard-release.pro'
configuration 'dexguard-project.txt'
configuration 'proguard-project.txt'
release
defaultConfiguration 'dexguard-release.pro'
configuration 'dexguard-project.txt'
configuration 'proguard-project.txt'
repositories
flatDir dirs 'libs'
dependencies
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
googleImplementation 'com.google.firebase:firebase-messaging:20.2.3'
googleImplementation 'com.google.firebase:firebase-core:17.4.4'
testImplementation 'junit:junit:4.12'
googleImplementation 'com.google.firebase:firebase-crashlytics:17.1.1'
googleImplementation 'com.google.firebase:firebase-crashlytics-ndk:17.1.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.clans:fab:1.6.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Number Picker
implementation "com.shawnlin:number-picker:2.4.8"
googleImplementation 'com.google.android.gms:play-services-maps:17.0.0'
googleImplementation 'com.google.android.gms:play-services-analytics:17.0.0'
googleImplementation 'com.google.android.libraries.places:places:2.1.0'
googleImplementation 'com.google.maps.android:android-maps-utils:0.5'
// implementation 'com.google.android.gms:play-services-ads:11.8.0'
googleImplementation 'com.google.android.gms:play-services-identity:17.0.0'
googleImplementation 'com.google.android.gms:play-services-gcm:17.0.0'
googleImplementation 'com.google.android.gms:play-services-location:17.0.0'
implementation files('src/main/libs/accessory-v2.4.0.jar')
implementation files('src/main/libs/sdk-v1.0.0.jar')
implementation(name: 'dexguard/dexguard-runtime', ext: 'aar')
// implementation 'com.android.support:multidex:1.0.3'
// HUAWEI
huaweiImplementation 'com.huawei.agconnect:agconnect-core:1.4.1.300'
huaweiImplementation 'com.huawei.hms:maps:5.0.1.300'
huaweiImplementation 'com.huawei.hms:location:5.0.0.301'
huaweiImplementation 'com.huawei.hms:site:5.0.3.302'
huaweiImplementation 'com.huawei.hms:hianalytics:5.0.3.300'
huaweiImplementation 'com.huawei.agconnect:agconnect-crash:1.4.1.300'
这里还有一张图片显示我将 dexguard 文件添加到 app/libs 文件夹中:
如您所见,我添加了 hms/gms 风格,并且在 v8 中运行良好。如您所知,由于 v8 版本,我们不得不将 com.android.tools.build:gradle 保留为 3.6,因为它不兼容。我看到 v9 现在支持 4+ 构建版本!
【问题讨论】:
【参考方案1】:这应该是一个非常简单的更改,您的类路径中列出了错误的插件版本。
改变
classpath 'com.guardsquare:dexguard-gradle-plugin:9.0.17'
到
classpath 'com.guardsquare:dexguard-gradle-plugin:1.0.17'
对于我的项目,我还从 com/ 目录中下载的 zip 文件夹中复制了所有内容(忽略我的版本,我还没有使用 9.0.17)
【讨论】:
你是一个救世主 :) 它有效。我怎么看不到!有趣的是,在应用程序构建文件中,我必须将 dexguard 块中的路径设置为根文件库。对于插件的完整根目录!以上是关于原因:org.gradle.api.internal.plugins.PluginApplicationException:无法应用插件 [id 'dexguard']的主要内容,如果未能解决你的问题,请参考以下文章
“'NSInternalInconsistencyException' 的替代原因,原因:'此 NSPersistentStoreCoordinator 没有持久存储。'”