youngjuning / issues

一寸欢喜 - 怕什么真理无穷,进一寸有一寸的欢喜
https://youngjuning.js.org
44 stars 4 forks source link

Unable to find a matching configuration of project :react-native-code-push #187

Closed youngjuning closed 1 year ago

youngjuning commented 5 years ago

问题

Execution failed for task ':app:lintVitalRelease'.
Could not resolve project :react-native-code-push.
Required by:
project :app
> Unable to find a matching configuration of project :react-native-code-push:
- Configuration 'debugApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'releaseStaging' and found incompatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found
compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Configuration 'debugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'releaseStaging' and found incompatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Configuration 'releaseApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'releaseStaging' and found incompatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Configuration 'releaseRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'releaseStaging' and found incompatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.

出现原因

使用 Android Studio 编译时报错 或 运行 react-native run-android --variant=staging 时报错

解决办法

修改 android/app/build.gradle,修改指导有两个:

  1. releaseStaging 和 release 除了 buildConfigField,其他配置一样
  2. 在 releaseStaging 中添加 matchingFallbacks = ['release', 'debug'] 避免 Android Studio 编辑出错(不用担心,后边我们会说如何使用)
buildTypes {
    debug {
        buildConfigField "String", "CODEPUSH_KEY", '""'
    }
    releaseStaging {
        matchingFallbacks = ['release', 'debug']
        buildConfigField "String", "CODEPUSH_KEY", '"LRcceeF7bWUb2aHmRoF26fozN6hTfd7531f1-ea0b-4829-94e7-35586f21eb25"'
        debuggable false // 是否debug
        aaptOptions.cruncherEnabled = false // 禁止Gradle检查PNG的合法性
        shrinkResources true // 移除无用的resource文件
        zipAlignEnabled true // 对齐zip
        signingConfig signingConfigs.release
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
    release {
        buildConfigField "String", "CODEPUSH_KEY", '"mmz0HOQHOTwqR7wU3k6CyjKhoZq-fd7531f1-ea0b-4829-94e7-35586f21eb25"'
        debuggable false // 是否debug
        aaptOptions.cruncherEnabled = false // 禁止Gradle检查PNG的合法性
        shrinkResources true // 移除无用的resource文件
        zipAlignEnabled true // 对齐zip
        signingConfig signingConfigs.release
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}
youngjuning commented 5 years ago

code-push 正确打包方式

Production

$ cd android && ./gradlew assembleRelease
$ cd android && ./gradlew installRelease

Staging

$ cd android && ./gradlew assembleReleaseStaging
$ cd android && ./gradlew installReleaseStaging
youngjuning commented 5 years ago
"devStaging": "react-native run-android --appIdSuffix releaseStaging",
youngjuning commented 5 years ago

参考

youngjuning commented 5 years ago

react-native-community/react-native-webview#198