Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:Cannot set readonly property: proguardFiles for class: com.android.build.gradle.managed.BuildType

Tags:

android

I am trying to run an AR sample app from: https://artoolkit.org/documentation/doku.php?id=4_Android:android_examples

I tried to open the project ARSimpleProj. But it gives me this error:

Error:Cannot set readonly property: proguardFiles for class: com.android.build.gradle.managed.BuildType

I am using Android Studio 2.2.2 and Gradle 2.14.1

Thanks!

like image 536
Jayson Tamayo Avatar asked Oct 24 '16 03:10

Jayson Tamayo


2 Answers

According to this description , in version 0.4.0 , '+=' was desabled and instead use ".add()" for it . So make the statement

proguardFiles += file('proguard-rules.pro')

change to

proguardFiles.add(file('proguard-rules.pro'))

and the error will disappear

The build.gradle file now looks like the following ...note the changes..there are 2-3 changes done but now working absolutely fine.The code is below:-

    apply plugin: 'com.android.model.application' 

    model {
        android {
            compileSdkVersion = 23
            buildToolsVersion = "23.0.2"
        defaultConfig.with {
            applicationId = "org.artoolkit.ar.samples.ARSimple"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            //Integer type incremented by 1 for every release, major or minor, to Google store
            versionName = "1.0" //Real fully qualified major and minor release description

            buildConfigFields.with {
                //Defines fields in the generated Java BuildConfig class, in this case, for
                create() {           //default config, that can be accessed by Java code
                    type = "int"     //e.g. "if (1 == BuildConfig.VALUE) { /*do something*/}".
                    name = "VALUE"
                    //See: [app or lib]/build/generated/source/buildConfig/[package path]/
                    value = "1"      //     BuildConfig.java
                }
            }
        }
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file('proguard-rules.pro'))
        }
    }

    android.productFlavors {
    }

    android.sources {
        main{
            jni {
                source {
                    srcDirs = ['src/main/nop']
                }
            }
        }
        main{
            jniLibs {
                source {
                    srcDirs = ['src/main/libs']
                }
            }
        }
    }
}
dependencies {
    compile project(':aRBaseLib')
}
like image 168
kartik Avatar answered Oct 14 '22 22:10

kartik


I got the same error last a few hours. I solved by changing build type as follow -

buildTypes {
        release {
            minifyEnabled false
            proguardFiles 'proguard-rules.pro'
        }
    } 

After that I deleted all ndk imported code line. So my build.gradle of aRSimple is -

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.1"

        defaultConfig.with {
            applicationId = "org.artoolkit.ar.samples.ARSimple"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            //Integer type incremented by 1 for every release, major or minor, to Google store
            versionName = "1.0" //Real fully qualified major and minor release description

            buildConfigFields.with {
                //Defines fields in the generated Java BuildConfig class, in this case, for
                create() {           //default config, that can be accessed by Java code
                    type = "int"     //e.g. "if (1 == BuildConfig.VALUE) { /*do something*/}".
                    name = "VALUE"
                    //See: [app or lib]/build/generated/source/buildConfig/[package path]/
                    value = "1"      //     BuildConfig.java
                }
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles 'proguard-rules.pro'
        }
    }

    android.productFlavors {
    }



    }


dependencies {
    //compile 'com.android.support:support-v4:23.0.1'
    //compile 'com.android.support:appcompat-v7:23.0.1' //Only required when the target device API level is greater than
    compile project(':aRBaseLib')
}                                                       //the compile and target of the app being deployed to the device

Then I create and copied all the .so library file into the jnilibs in applicaion main folder as show in fig

fig

Then run yours. I don't know this is the solution for this. But the errors go and project run without errors. Tell me if you find any other solution for this. Thanks.

like image 7
San Ko Ko Avatar answered Oct 14 '22 22:10

San Ko Ko