错误移植gradle:2.0.0到gradle-experimental:0.7.0-beta1?

时间:2016-04-14 19:21:10

标签: android gradle gradle-experimental

我有一个android工作室项目,我正在尝试将gradle从稳定版本2.0.0移植到实验版本0.7.0-beta1:

这是我的android标签模块中的工作代码我的2.0.0 gradle代码:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.test.myapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        ndk {
            moduleName "myNativeLib"
        }
    }

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs' //set .so files location to libs
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

    task runSwig(type: Exec, description: 'Run swig config') {
        workingDir 'src/main'
        commandLine 'cmd', '/c', 'swig.bat'
    }

    Properties props = new Properties()
    props.load(new FileInputStream(file(project.property("KeyStore.properties"))))

    signingConfigs {
        storeSignature {
            storeFile = file(props['KEYSTORE'])
            storePassword = props['KEYSTORE_PASSWD']
            keyAlias = props['KEYSTORE_MYAPP']
            keyPassword = props['KEYSTORE_MYAPP_PASSWD']
        }
    }

    buildTypes {
        def SERVER_URL = "SERVER_URL"
        debug {
            debuggable true
            jniDebuggable true
            buildConfigField "String", SERVER_URL, "\"http://testusound.eastus.cloudapp.azure.com/androidbackend/checkjson\""
            versionNameSuffix getMasterName() + "." + getDate()
        }        

        release {
            signingConfig signingConfigs.storeSignature
            debuggable false
            jniDebuggable false
            minifyEnabled false
            buildConfigField "String", SERVER_URL, "\"http://www.usound.co/androidbackend/checkjson\""
            versionNameSuffix getMasterName()
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

现在我尝试重写我的expermiental插件0.7.0-beta1的代码:

model {
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.3"

        defaultConfig.with {
            applicationId "com.test.myapp"
            minSdkVersion.apiLevel 15
            targetSdkVersion.apiLevel 23
            versionCode 1
            versionName "1.0"
        }

        ndk {
            moduleName "myNativeLib"
        }

        tasks.withType(JavaCompile) {
            compileTask -> compileTask.dependsOn ndkBuild
        }   

        task runSwig(type: Exec, description: 'Run swig config') {
            workingDir 'src/main'
            commandLine 'cmd', '/c', 'swig.bat'
        }

        buildConfigFields.with {
            create() {
                type "String"
                name "SERVER_URL"
                value "\"http://www.myserver.com/backend/checkjson\""
            }
        }

        buildConfigFields.with {
            create() {
                type "String"
                name "TEST_SERVER_URL"
                value "\"http://www.mytestserver.com/backend/checkjson\""
            }
        }

        sources {
            main {
                jni {
                    source {
                        srcDir "src"
                    }
                }
                jni.srcDirs = [] //disable automatic ndk-build call
            }
         }

         buildTypes {
            debug {
                debuggable true
                jniDebuggable true
                buildConfigField $("android.buildConfigFields.TEST_SERVER_URL")
                versionNameSuffix getMasterName() + "." + getDate()
            }
            release {
                signingConfig = $("android.signingConfigs.mySignature")
                debuggable false
                jniDebuggable false
                minifyEnabled false
                buildConfigField $("android.buildConfigFields.SERVER_URL")
                versionNameSuffix getMasterName()
                proguardFiles.add(file('proguard-rules.pro'))
            }
         }
         Properties props = new Properties()
         props.load(new FileInputStream(file(project.property("KeyStore.properties"))))
     }

     android.signingConfigs {
        create("mySignature")
        storeFile = file(props['KEYSTORE'])
        storePassword = props['KEYSTORE_PASSWD']
        keyAlias = props['KEYSTORE_MYAPP']
        keyPassword = props['KEYSTORE_MYAPP_PASSWD']
     }
}

我在使用signingConfigs时遇到此错误:

Error:Attempt to read a write only view of model of type 'java.lang.Object' given to rule 'android.signingConfigs { ... } @ app\build.gradle line 165, column 5'
我的代码中的

就是这一行:

android.signingConfigs {

对于我的签名配置我正在使用一个名为keystore.properties的文件位于我的主文件夹下(我想将它保存在一个单独的文件中,所以我不会将我的密钥库签名数据上传到git,所以我没有把签名配置键放在当前的实验gradle项目中。)

我在这里缺少什么?我应该如何编写签名配置以使用从文件加载的属性? 因为我刚刚进入实验学习阶段,请随时给我一些您认为可能有用的示例或信息。

1 个答案:

答案 0 :(得分:0)

创建后的内容应该在{}

的一组中
 android.signingConfigs {
    create("mySignature") {  // <-- needed
      storeFile = file(props['KEYSTORE'])
      storePassword = props['KEYSTORE_PASSWD']
      keyAlias = props['KEYSTORE_MYAPP']
      keyPassword = props['KEYSTORE_MYAPP_PASSWD']
    }  // <-- needed
 }