【问题标题】:Gradle: Could not get unknown propertyGradle:无法获得未知属性
【发布时间】:2021-09-14 00:51:26
【问题描述】:

已经定义了所需的存储库变量。

这是管道中的 Gradle 包装器命令

- step:
        name: Create Keystores and Google Play API key file
        script:
          - mkdir keys # create new directory
          - echo $DEBUG_KEYSTORE_FILE_BASE64 | base64 -d > keys/$DEBUG_KEYSTORE_FILE # decode base64 then use DEBUG_KEYSTORE_FILE as file name defined in repository variable
          - echo $KEYSTORE_FILE_BASE64 | base64 -d > keys/$KEYSTORE_FILE # decode base64 then use KEYSTORE_FILE as file name defined in repository variable
          - echo $GOOGLE_PLAY_API_KEY_BASE64 | base64 -d > keys/$GOOGLE_PLAY_API_KEY_FILE # decode base64 then use GOOGLE_PLAY_API_KEY_FILE as file name defined in repository variable
        artifacts:
          - keys/** # keep these artifacts for subsequent pipeline steps

- step:
        name: Build & Deploy (Internal)
        caches: # caching speed up subsequent execution https://support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/
          - gradle
        script:
          # publish the aab file to the internal testing channel
          # the plugin publishes to the internal testing track by default
          - chmod +x gradlew
          - "./gradlew
                       -PANDROID_BUILD_COMPILED_SDK_VERSION=$ANDROID_BUILD_COMPILED_SDK_VERSION
                       -PANDROID_BUILD_MIN_SDK_VERSION=$ANDROID_BUILD_MIN_SDK_VERSION
                       -PANDROID_BUILD_TARGET_SDK_VERSION=$ANDROID_BUILD_TARGET_SDK_VERSION

                       -PDEBUG_KEYSTORE_FILE=../keys/$DEBUG_KEYSTORE_FILE
                       -PDEBUG_KEYSTORE_PASSWORD=$DEBUG_PASSWORD
                       -PDEBUG_KEYSTORE_KEY_ALIAS=$DEBUG_KEY_ALIAS
                       -PDEBUG_KEYSTORE_KEY_PASSWORD=$DEBUG_KEY_PASSWORD

                       -PAPPNAME_KEYSTORE_FILE=../keys/$KEYSTORE_FILE
                       -PAPPNAME_KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD
                       -PAPPNAME_KEY_ALIAS=$KEYSTORE_KEY_ALIAS
                       -PAPPNAME_KEY_PASSWORD=$KEY_PASSWORD

                       -PGOOGLE_PLAY_API_KEY=../keys/$GOOGLE_PLAY_API_KEY

                       -PBUILD_NUMBER=$BITBUCKET_BUILD_NUMBER

                        clean :app:publishReleaseBundle"
        artifacts:
          - app/build/outputs/ # artifacts are files that are produced by a step https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/

问题是 -PDEBUG_KEYSTORE_FILE=../keys/$DEBUG_KEYSTORE_FILE 在构建过程中有些被忽略并且无法正常工作。

Build setup5s

chmod +x gradlew<1s

./gradlew -PANDROID_BUILD_COMPILED_SDK_VERSION=$ANDROID_BUILD_COMPILED_SDK_VERSION -PANDROID_BUILD_MIN_SDK_VERSION=$ANDROID_BUILD_MIN_SDK_VERSION -PANDROID_BUILD_TARGET_SDK_VERSION=$ANDROID_BUILD_TARGET_SDK_VERSION -PDEBUG_KEYSTORE_FILE=../keys/$DEBUG_KEYSTORE_FILE -PDEBUG_KEYSTORE_PASSWORD=$DEBUG_PASSWORD -PDEBUG_KEYSTORE_KEY_ALIAS=$DEBUG_KEY_ALIAS -PDEBUG_KEYSTORE_KEY_PASSWORD=$DEBUG_KEY_PASSWORD -PAPPNAME_KEYSTORE_FILE=../keys/$KEYSTORE_FILE -PAPPNAME_KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD -PAPPNAME_KEY_ALIAS=$KEYSTORE_KEY_ALIAS -PAPPNAME_KEY_PASSWORD=$KEY_PASSWORD -PGOOGLE_PLAY_API_KEY=../keys/$GOOGLE_PLAY_API_KEY -PBUILD_NUMBER=$BITBUCKET_BUILD_NUMBER clean :app:publishFreeReleaseBundle39s

+ ./gradlew -PANDROID_BUILD_COMPILED_SDK_VERSION=$ANDROID_BUILD_COMPILED_SDK_VERSION -PANDROID_BUILD_MIN_SDK_VERSION=$ANDROID_BUILD_MIN_SDK_VERSION -PANDROID_BUILD_TARGET_SDK_VERSION=$ANDROID_BUILD_TARGET_SDK_VERSION
-PDEBUG_KEYSTORE_FILE=../keys/$DEBUG_KEYSTORE_FILE -PDEBUG_KEYSTORE_PASSWORD=$DEBUG_PASSWORD -PDEBUG_KEYSTORE_KEY_ALIAS=$DEBUG_KEY_ALIAS -PDEBUG_KEYSTORE_KEY_PASSWORD=$DEBUG_KEY_PASSWORD
-PAPPNAME_KEYSTORE_FILE=../keys/$KEYSTORE_FILE -PAPPNAME_KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD -PAPPNAME_KEY_ALIAS=$KEYSTORE_KEY_ALIAS -PAPPNAME_KEY_PASSWORD=$KEY_PASSWORD
-PGOOGLE_PLAY_API_KEY=../keys/$GOOGLE_PLAY_API_KEY
-PBUILD_NUMBER=$BITBUCKET_BUILD_NUMBER
clean :app:publishFreeReleaseBundle
Downloading https://services.gradle.org/distributions/gradle-7.0-bin.zip
...........................................................................................................
Unzipping /root/.gradle/wrapper/dists/gradle-7.0-bin/2p9ebqfz6ilrfozi676ogco7n/gradle-7.0-bin.zip to /root/.gradle/wrapper/dists/gradle-7.0-bin/2p9ebqfz6ilrfozi676ogco7n
Set executable permissions for: /root/.gradle/wrapper/dists/gradle-7.0-bin/2p9ebqfz6ilrfozi676ogco7n/gradle-7.0/bin/gradle
Welcome to Gradle 7.0!
Here are the highlights of this release:
 - File system watching enabled by default
 - Support for running with and building Java 16 projects
 - Native support for Apple Silicon processors
 - Dependency catalog feature preview
For more details see https://docs.gradle.org/7.0/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Build file '/opt/atlassian/pipelines/agent/build/app/build.gradle' line: 27
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'DEBUG_KEYSTORE_FILE' for SigningConfig_Decorated{name=debug, storeFile=/opt/android-sdk-linux/.android/debug.keystore, storePassword=android, keyAlias=AndroidDebugKey, keyPassword=android, storeType=pkcs12, v1SigningEnabled=true, v2SigningEnabled=true, enableV1Signing=null, enableV2Signing=null, enableV3Signing=null, enableV4Signing=null} of type com.android.build.gradle.internal.dsl.SigningConfig.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 39s

但是为了进一步测试它,我尝试删除 -PANDROID_BUILD_COMPILED_SDK_VERSION=$ANDROID_BUILD_COMPILED_SDK_VERSION 参数,错误现在出现在 compileSdk 上

FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file '/opt/atlassian/pipelines/agent/build/app/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'ANDROID_BUILD_COMPILED_SDK_VERSION' for extension 'android' of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings
* Get more help at https://help.gradle.org
BUILD FAILED in 39s

有了这个,我认为这个参数可以正常工作,但是在签名时,我自己的签名配置似乎被忽略了。

这是应用程序 Gradle 文件的样子。

android {
    compileSdk Integer.parseInt(ANDROID_BUILD_COMPILED_SDK_VERSION)

    defaultConfig {
        applicationId "com.app.name"
        minSdk Integer.parseInt(ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdk Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)
        versionCode project.hasProperty('BUILD_NUMBER') ? project['BUILD_NUMBER'].toInteger() : 14
        versionName "1.3.3"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            storeFile file(DEBUG_KEYSTORE_FILE)
            storePassword DEBUG_KEYSTORE_PASSWORD
            keyAlias DEBUG_KEYSTORE_KEY_ALIAS
            keyPassword DEBUG_KEYSTORE_KEY_PASSWORD
        }
        release {
            storeFile file(APPNAME_KEYSTORE_FILE)
            storePassword APPNAME_KEYSTORE_PASSWORD
            keyAlias APPNAME_KEYSTORE_KEY_ALIAS
            keyPassword APPNAME_KEYSTORE_KEY_PASSWORD
        }
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled true
            shrinkResources true
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            signingConfig signingConfigs.debug
        }
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            signingConfig signingConfigs.release
        }
    }

    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    lintOptions {
        disable "MissingClass"
    }

    buildFeatures {
        viewBinding true
    }
}

play {
    serviceAccountCredentials.set(file(GOOGLE_PLAY_API_KEY_FILE))
}

更新: 似乎它并不特定于调试签名,但也与我得到的版本有关 Could not get unknown property 'APPNAME_KEYSTORE_FILE'

在 Android Studio 终端本地运行它可以工作,但在管道中它不起作用。

如果文件路径或位置有问题,则错误消息不应Could not get unknown property

【问题讨论】:

  • 你在哪个文件中存储 DEBUG_KEYSTORE_FILE 这些变量的值?
  • @manmohan 你可以在Create Keystores and Google Play API key file上面看到它
  • @BitwiseDEVS 你解决了吗不匹配,顺便说一句,我正在使用下一个命令 keytool -printcert -jarfile app-debug.apk
  • @V1t0r14n0 您需要使用相同的密钥库,以便本地和管道中的签名和 SHA 相同。为此,您需要将您的密钥库文件转换为 base64,然后对其进行解码并在构建期间为其创建一个工件文件。

标签: android gradle android-gradle-plugin gradlew bitbucket-pipelines


【解决方案1】:

先去掉间距

-PANDROID_BUILD_TARGET_SDK_VERSION=$ANDROID_BUILD_TARGET_SDK_VERSION

-PDEBUG_KEYSTORE_FILE=../keys/$DEBUG_KEYSTORE_FILE

下到

-PBUILD_NUMBER=$BITBUCKET_BUILD_NUMBER

clean :app:publishReleaseBundle

正如您指出的那样,-PANDROID_BUILD_COMPILED_SDK_VERSION 正在工作,那里应该没有空间。换行会使命令不完整。

它将解决您当前的问题,但是您会遇到另一个问题,因为您的环境变量与命令任务和 Bitbucket 存储库变量页面不匹配。在命令或网站上更改您的变量名称。

在 BB 页面中,您没有名为 DEBUG_KEY_PASSWORD 的变量。

仔细检查命令任务和 Bitbucket 存储库变量中的其他变量和属性,您可能还会错过另一个。

【讨论】:

  • 是的!这是正确的,那些血腥的空间,感谢您检查变量以及我发现另一个不匹配。
【解决方案2】:

按照https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html,在您的规范中使用bamboo_ 为Bamboo 变量添加前缀。例如$DEBUG_KEYSTORE_FILE 变为$bamboo_DEBUG_KEYSTORE_FILE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    相关资源
    最近更新 更多