Android 原因:org.gradle.api.internal.plugins.PluginApplicationException:未能应用插件[id';dexguard';]

Android 原因:org.gradle.api.internal.plugins.PluginApplicationException:未能应用插件[id';dexguard';],android,gradle,proguard,dexguard,Android,Gradle,Proguard,Dexguard,我正在Android项目中将Dexguard从v8升级到最新版本9.0.17。直到现在,一切都很顺利,但现在我需要你的帮助 在完成了关于如何在Android Studio和重建项目中从v8升级到v9的教程之后,我发现了一个错误:,原因是:org.gradle.api.internal.plugins.PluginApplicationException:未能应用插件[id'dexguard'] 我不知道发生了什么事。我尝试了许多组合来修复它并使其工作,但没有成功。她是我的档案: build.gr

我正在Android项目中将Dexguard从v8升级到最新版本9.0.17。直到现在,一切都很顺利,但现在我需要你的帮助

在完成了关于如何在Android Studio和重建项目中从v8升级到v9的教程之后,我发现了一个错误:,原因是:org.gradle.api.internal.plugins.PluginApplicationException:未能应用插件[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(应用程序)文件->:


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+版本


谢谢你的帮助

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

改变

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

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

你是救世主:)这很有效。我怎么能看不到呢!有趣的是,在应用程序构建文件中,我必须在dexguard块中设置根文件libs的路径。和插件完整根到它!
classpath 'com.guardsquare:dexguard-gradle-plugin:1.0.17'