1

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

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

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

现在这是我为实验插件 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']
     }
}

我在签名配置中收到此错误错误:

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 项目中)。

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

4

1 回答 1

0

创建后的东西应该在一组 {} 中

 android.signingConfigs {
    create("mySignature") {  // <-- needed
      storeFile = file(props['KEYSTORE'])
      storePassword = props['KEYSTORE_PASSWD']
      keyAlias = props['KEYSTORE_MYAPP']
      keyPassword = props['KEYSTORE_MYAPP_PASSWD']
    }  // <-- needed
 }
于 2016-06-16T13:34:47.417 回答