微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

引起:org.gradle.api.internal.plugins.PluginApplicationException: 无法应用插件 [id 'dexguard']

如何解决引起:org.gradle.api.internal.plugins.PluginApplicationException: 无法应用插件 [id 'dexguard']

我正在 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","IS_USER_TESTER","IS_GEAR_ENABLED","true"
        }
        create("appProduction") {
            applicationId = "com.xxxx.project"
            dimension "appID"

            signingConfig = null
            buildConfigField "boolean","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 文件夹中:

enter image description here

如您所见,我添加了 hms/gms 风味,并且在 v8 中运行良好。您可能知道,由于 v8 版本,我们不得不将 com.android.tools.build:gradle 保留为 3.6,因为它不兼容。我看到 v9 现在支持 4+ 构建版本!

感谢您的帮助!

解决方法

这应该是一个非常简单的更改,您的类路径中列出了错误的插件版本。

改变

classpath 'com.guardsquare:dexguard-gradle-plugin:9.0.17'

classpath 'com.guardsquare:dexguard-gradle-plugin:1.0.17'

对于我的项目,我还从 com/ 目录中下载的 zip 文件夹中复制了所有内容(忽略我的版本,我还没有使用 9.0.17)

file listing

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。