简体   繁体   中英

Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'dexguard']

I am upgrading Dexguard from v8 to latest version 9.0.17 in Android project. Until now, everything was working well, but now I need your help.

After following tutorial how to upgrade from v8 to v9 in Android Studio and rebuilding project, I am getting error: Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'dexguard']

I am not sure what is going on. I tried many combos to fix it and make it work but with no success. Her are my files: 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
}

and build.gradle(app) file ->:


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'
}

Here is also an image to show that I added dexguard files into app/libs folder:

在此处输入图像描述

As you can see, I have hms/gms flavor added and with v8 it was working fine. As you may know, because of v8 version we had to leave com.android.tools.build:gradle to 3.6, because it was incompatible. I see that v9 now supports 4+ build version!

Thanks for any help!

This should be a pretty simple change, you have the wrong plugin version listed on your classpath.

Change

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

to

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

For my project I also copied everything from the downloaded zip folder inside the com/ directory (ignore my version i am not on 9.0.17 yet)

文件列表

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM