React Native 构建在构建调试/发布以外的新构建类型时失败

Aya*_*yan 5 android react-native

我正在尝试准备一个临时发布版本,但我的构建失败了。它给了我一大堆错误。我已经修改了我的 build.gradle 以添加一个临时环境。我不确定为什么会发生这种情况,因为我的调试和发布版本工作正常。

我曾经yarn android --variant=stagingrelease生成构建并在我的物理 android 设备上运行。使用React-Native: 0.61.5.

部分错误如下

FAILURE: Build failed with an exception.

* What went wrong: Could not determine the dependencies of task ':app:preStagingreleaseBuild'.
> Could not resolve all task dependencies for configuration ':app:stagingreleaseRuntimeClasspath'.
   > Could not resolve project :@react-native-community_masked-view.
     Required by:
         project :app
      > Unable to find a matching variant of project :@react-native-community_masked-view:
          - Variant 'debugApiElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'debugRuntimeElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseApiElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseRuntimeElements' capability Furry:@react-native-community_masked-view:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - 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'.
   > Could not resolve project :react-native-bootsplash.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-bootsplash:
          - Variant 'debugApiElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseApiElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-bootsplash:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - 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'.
   > Could not resolve project :react-native-config.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-config:
          - Variant 'debugApiElements' capability Furry:react-native-config:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-config:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseApiElements' capability Furry:react-native-config:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-config:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - 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'.
   > Could not resolve project :react-native-gesture-handler.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-gesture-handler:
          - Variant 'debugApiElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseApiElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-gesture-handler:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - 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'.
   > Could not resolve project :react-native-reanimated.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-reanimated:
          - Variant 'debugApiElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'debugRuntimeElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseApiElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseRuntimeElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - 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'.
   > Could not resolve project :react-native-safe-area-context.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-safe-area-context:
          - Variant 'debugApiElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'debugRuntimeElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseApiElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseRuntimeElements' capability Furry:react-native-safe-area-context:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - 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'.
   > Could not resolve project :react-native-screens.
     Required by:
         project :app
      > Unable to find a matching variant of project :react-native-screens:
          - Variant 'debugApiElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'debugRuntimeElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseApiElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - 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'.
          - Variant 'releaseRuntimeElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
              - Incompatible attribute:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
              - Other attributes:
                  - 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'.
Run Code Online (Sandbox Code Playgroud)

android/app/build.gradle 的片段

project.ext.envConfigFiles = [
        debug: ".env",
  

Aya*_*yan 20

好吧!,所以我已经尝试了很多小时来解决这些问题,结果发现有一个简单的答案,matchingFallbacks.

出现问题是因为我stagingrelease向我的应用程序添加了一个新的构建变体,build.gradle而正在使用的本机库中没有相同的匹配变体,build.gradle因此在构建过程中找不到相应的库。

stagingrelease {
    initWith release
    matchingFallbacks = ['debug', 'release'] // Addded this
}
Run Code Online (Sandbox Code Playgroud)