Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

android - could not get unknown property for 'applicationVariants' for BuildType_Decorated

I have imported the module in my project and its correctly imported. But i am getting this error. i have imported the Scanner control app module (By zebra). I have searched for many alternated solutions, but it's not working out.

Error:(36, 0) Could not get unknown property 'applicationVariants' for BuildType_Decorated{name=release, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, minifyEnabled=false, zipAlignEnabled=true, signingConfig=null, embedMicroApp=true, mBuildConfigFields={}, mResValues={}, mProguardFiles=[/home/custom/AndroidStudioProjects/fireball5/fireball/build/intermediates/proguard-files/proguard-android.txt-2.3.3, /home/custom/AndroidStudioProjects/fireball5/fireball/scannercontrol/proguard-rules.pro], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.BuildType.
<a href="openFile:/home/custom/AndroidStudioProjects/fireball5/fireball/scannercontrol/build.gradle">Open File</a>
    apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.zebra.scannercontrol.app"
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 71
        versionName "2.0.8.0"
        if (project.hasProperty('ADD_BUILD_TO_VERSION')) {
            versionName = versionName.substring(0,versionName.lastIndexOf(".") + 1) + (System.getenv("BUILD_NUMBER") ?: "0")
        }
    }

    signingConfigs {
        release {
            storeFile file("../../../keys/AndroidScannerSDK.keystore")
            if (project.hasProperty('RELEASE_STORE_PASSWORD')) {
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            if (project.hasProperty('RELEASE_STORE_PASSWORD')) {
                signingConfig signingConfigs.release
            }
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                appendVersionName(variant, defaultConfig)
            }
        }
    }

    lintOptions {
        // Don't abort if Lint finds an error, otherwise the Jenkins build
        // will be marked as failed, and Jenkins won't analyse the Lint output
        abortOnError false
    }
}
def appendVersionName(variant, defaultConfig) {
    variant.outputs.each { output ->
        if (output.zipAlign) {
            def file = output.outputFile
            def fileName = file.name.replace("scannercontrol-release.apk", "scanner_control_app_v" + defaultConfig.versionName  + ".apk")
            output.outputFile = new File(file.parent, fileName)
        }

        def file = output.packageApplication.outputFile
        def fileName = file.name.replace("scannercontrol-release", "scanner_control_app_v" + defaultConfig.versionName + ".apk")
        output.packageApplication.outputFile = new File(file.parent, fileName)
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile project(':BarcodeScannerLibrary')
}
enter code here
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have an error at applicationVariants.all.

buildTypes {
    release {
        applicationVariants.all { variant ->
            appendVersionName(variant, defaultConfig)
        }
    }
}

Fix 1:

This will not work since you are applying apply plugin: 'com.android.library'.

You have to change it to apply plugin: 'com.android.application' to use applicationVariants.all.

Fix 2:

If you want to keep using apply plugin: 'com.android.library'.

Change applicationVariants.all to libraryVariants.all or testVariants.all.

Explanation:

applicationVariants (only for the app plugin)

libraryVariants (only for the library plugin)

testVariants (for both plugins)

All three return a DomainObjectCollection of ApplicationVariant, LibraryVariant, and TestVariant objects respectively.

Hope this helps.

Edit:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 71
        versionName "2.0.8.0"
        if (project.hasProperty('ADD_BUILD_TO_VERSION')) {
            versionName = versionName.substring(0,versionName.lastIndexOf(".") + 1) + (System.getenv("BUILD_NUMBER") ?: "0")
        }
    }

    signingConfigs {
        release {
            storeFile file("../../../keys/AndroidScannerSDK.keystore")
            if (project.hasProperty('RELEASE_STORE_PASSWORD')) {
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            if (project.hasProperty('RELEASE_STORE_PASSWORD')) {
                signingConfig signingConfigs.release
            }
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile project(':BarcodeScannerLibrary')
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...