错误:无法设置readonly属性:proguardFiles for class:com.android.build.gradle.managed.BuildType

时间:2016-10-24 03:03:41

标签: android

我正在尝试从https://artoolkit.org/documentation/doku.php?id=4_Android:android_examples

运行AR示例应用

我试图打开项目ARSimpleProj。但它给了我这个错误:

    @IBOutlet weak var imageView: UIImageView!
    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    imageView.isUserInteractionEnabled = true
    let panGestureRecognizer = UIPanGestureRecognizer(target:self, action: #selector(panHandler(recognizer:)))
         imageView.addGestureRecognizer(panGestureRecognizer)
    }

    func panHandler(recognizer:UIPanGestureRecognizer) {
    let translation = recognizer.translation(in: view)
    recognizer.view!.center = CGPoint(x: recognizer.view!.center.x + translation.x, y: recognizer.view!.center.y + translation.y)
    recognizer.setTranslation(CGPoint.zero, in: view)
   }

我使用的是Android Studio 2.2.2和Gradle 2.14.1

谢谢!

3 个答案:

答案 0 :(得分:8)

根据 Here,在版本0.4.0中,'+ ='被删除,而是使用“.add()”。 所以发表声明

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

更改为

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

并且错误将消失

build.gradle文件现在看起来如下...请注意更改...已完成2-3个更改 但现在工作得很好。代码如下: -

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

答案 1 :(得分:7)

我在几个小时内得到了同样的错误。我通过改变构建类型解决了 -

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

之后我删除了所有ndk导入的代码行。所以我的build.gradle的aRSimple是 -

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

然后我创建并将所有.so库文件复制到应用程序主文件夹中的jnilibs中,如图所示

fig

然后运行你的。 我不知道这是解决方案。但错误发生,项目运行没有错误。如果您找到任何其他解决方案,请告诉我。感谢。

答案 2 :(得分:0)

Github获取文件为我修复了它。为了将文件链接到保存SDK的位置并从该目录中重新打开,我按照他们的简短阅读方式进行了操作。我无法得到上述答案为我工作。也许有些事情发生了变化,因为我拥有所有的.so libs;否则我做错了。