无法转换react-native-0.71.0-rc.0-release.aar(com.facebook.react:react-native:0.71.0-rc.0)以匹配属性

问题描述 投票:0回答:4

我收到此错误:

   > Failed to transform react-native-0.71.0-rc.0-release.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-art-profile, com.android.build.api.attributes.BuildTypeAttr=release, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not find react-native-0.71.0-rc.0-release.aar (com.facebook.react:react-native:0.71.0-rc.0).
        Searched in the following locations:
            https://jcenter.bintray.com/com/facebook/react/react-native/0.71.0-rc.0/react-native-0.71.0-rc.0-release.aar

当我尝试通过点击以下命令在 Android 上创建捆绑包时: “ENV=生产 ./envscript.sh && ENVFILE=.env.生产 && cd android && npx react-native run-android --mode=ProductionRelease && ./gradlew bundleRelease”

在某些时候,当我尝试升级react-native或尝试将

apply plugin: "com.facebook.react"
添加到build.gralde时,我收到错误消息:
... Could not find Hermes.so
SoLoader: couldn't find DSO to load ...
Plugin with id 'com.facebook.react' not found

envscript.sh 仅指定 google-services 文件位置

我还尝试在不久前在我的分支上运行的阶段点击bundleRelease命令,但它不起作用!

  • 将react-native升级到v0.72.0,但它也没有修复错误...
  • 所有建议的东西都在这里
这是

react-native info

 给我的:

System: OS: macOS 13.4 CPU: (8) arm64 Apple M1 Pro Memory: 1.61 GB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.2.0 - /usr/local/bin/node Yarn: Not Found npm: 9.6.6 - /usr/local/bin/npm Watchman: Not Found Managers: CocoaPods: 1.12.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4 Android SDK: API Levels: 28, 29, 30, 31, 32, 33 Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 33.0.0, 34.0.0 System Images: android-28 | Google APIs ARM 64 v8a, android-28 | Google ARM64-V8a Play ARM 64 v8a, android-29 | Google APIs ARM 64 v8a, android-29 | Google Play ARM 64 v8a, android-30 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a, android-33 | Google Play ARM 64 v8a Android NDK: 22.1.7171670 IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7935034 Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild Languages: Java: 17.0.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.6 => 0.71.6 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found
这是 android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { minSdkVersion = 23 compileSdkVersion = 33 targetSdkVersion = 31 supportLibVersion = "28.0.0" } repositories { google() jcenter() } dependencies { classpath('com.android.tools.build:gradle:7.0.4') classpath 'com.google.gms:google-services:4.3.10' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:1.3.0" } } allprojects { repositories { mavenLocal() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } google() jcenter() maven { url 'https://www.jitpack.io' } } }
android/app/build.gradle:

apply plugin: "com.android.application" apply plugin: 'com.google.gms.google-services' project.ext.envConfigFiles = [ productiondebug: ".env.production", productionrelease: ".env.production", developmentrelease: ".env.development", developmentdebug: ".env.development", stagingrelease: ".env.staging", stagingdebug: ".env.staging" ] apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" import com.android.build.OutputFile import groovy.json.JsonSlurper project.ext.react = [ enableHermes: false, // clean and rebuild if changing ] apply from: "../../node_modules/react-native/react.gradle" def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = true def jscFlavor = 'org.webkit:android-jsc:+' def enableHermes = project.ext.react.get("enableHermes", false); def getPackageJsonObjectFromNpm() { def inputFile = new File("$rootDir/../package.json") def packageJson = new JsonSlurper().parseText(inputFile.text) return packageJson } def getVersionCodeFromNpm() { return getPackageJsonObjectFromNpm()["Android"]["versionCode"] } def getVersionNameFromNpm() { return getPackageJsonObjectFromNpm()["Android"]["versionName"] } def getPassword(String currentUser, String keyChain) { def stdout = new ByteArrayOutputStream() def stderr = new ByteArrayOutputStream() exec { commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w' standardOutput = stdout errorOutput = stderr ignoreExitValue true } stdout.toString().trim() } def pass = getPassword("PASSWORD","android_keystore_PASSWORD") android { compileSdkVersion rootProject.ext.compileSdkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled true versionCode getVersionCodeFromNpm() versionName getVersionNameFromNpm() manifestPlaceholders = [ANDROID_GEO_API_KEY: "$System.env.ANDROID_GEO_API_KEY"] applicationId "com.example.equitazone" } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } signingConfigs { debug { storeFile file('debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } release { if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) { storeFile file(MYAPP_UPLOAD_STORE_FILE) storePassword MYAPP_UPLOAD_STORE_PASSWORD keyAlias MYAPP_UPLOAD_KEY_ALIAS keyPassword MYAPP_UPLOAD_KEY_PASSWORD } } } buildTypes { debug { signingConfig signingConfigs.debug matchingFallbacks = ['debug', 'release'] } release { signingConfig signingConfigs.release debuggable false minifyEnabled true shrinkResources true zipAlignEnabled true setProguardFiles([getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro']) ndk { debugSymbolLevel = 'FULL' } } } flavorDimensions "default" productFlavors { production { } staging { } development { } } applicationVariants.all { variant -> variant.outputs.each { output -> def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } packagingOptions { pickFirst '**/libjsc.so' pickFirst '**/libc++_shared.so' pickFirst '**/libfbjni.so' } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.facebook.react:react-native:0.63.4" implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { exclude group:'com.facebook.fbjni' } debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' } if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") } else { implementation jscFlavor } implementation platform('com.google.firebase:firebase-bom:31.2.1') implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-analytics:17.3.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.google.android.gms:play-services-location:18.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0' implementation project(':react-native-vector-icons') implementation project(':react-native-push-notification') } task copyDownloadableDepsToLibs(type: Copy) { from configurations.implementation into 'libs' } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
我的MainApplication.java:

package com.mariongourlaouen.equitazone; import android.app.Application; import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.soloader.SoLoader; import java.lang.reflect.InvocationTargetException; import androidx.multidex.MultiDexApplication; import java.util.List; // import androidx.appcompat.app.AppCompatActivity; public class MainApplication extends MultiDexApplication implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List<ReactPackage> getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List<ReactPackage> packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: // packages.add(new MyReactNativePackage()); return packages; } @Override protected String getJSMainModuleName() { return "index"; } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } /** * Loads Flipper in React Native templates. Call this in the onCreate method with something like * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); * * @param context * @param reactInstanceManager */ private static void initializeFlipper( Context context, ReactInstanceManager reactInstanceManager) { if (BuildConfig.DEBUG) { try { /* We use reflection here to pick up the class that initializes Flipper, since Flipper library is not available in release mode */ Class<?> aClass = Class.forName("com.mariongourlaouen.equitazone.ReactNativeFlipper"); aClass .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) .invoke(null, context, reactInstanceManager); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } }
知道我可以做什么来

最终创建我的捆绑包吗?请帮助我🙏🏻

android react-native
4个回答
2
投票
react-native-0.71.0-rc 在 Jcenter 上可用, 但今天(2023年6月23日)Jcenter停止服务了,

2021年2月3日jFrog宣布将关闭Jcenter

所以只需升级你的react-native版本并检查React-native的稳定版本,并尝试从Android文件夹中的build.gradle文件中删除Jcenter()

您也可以查看此链接

https://github.com/facebook/react-native/releases/tag/v0.71.0-rc.0 https://developer.android.com/build/jcenter-migration

jcneter 状态:

https://status.gradle.com/


0
投票
以下是更新的文件: android/app/build.gradle:

apply plugin: "com.android.application" apply plugin: "com.facebook.react" apply plugin: 'com.google.gms.google-services' project.ext.envConfigFiles = [ productiondebug: ".env.production", productionrelease: ".env.production", developmentrelease: ".env.development", developmentdebug: ".env.development", stagingrelease: ".env.staging", stagingdebug: ".env.staging" ] apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" import com.android.build.OutputFile import groovy.json.JsonSlurper project.ext.react = [ enableHermes: false, // clean and rebuild if changing ] // apply from: "../../node_modules/react-native/react.gradle" def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = true def jscFlavor = 'org.webkit:android-jsc:+' def enableHermes = project.ext.react.get("enableHermes", false); def getPackageJsonObjectFromNpm() { def inputFile = new File("$rootDir/../package.json") def packageJson = new JsonSlurper().parseText(inputFile.text) return packageJson } def getVersionCodeFromNpm() { return getPackageJsonObjectFromNpm()["Android"]["versionCode"] } def getVersionNameFromNpm() { return getPackageJsonObjectFromNpm()["Android"]["versionName"] } def getPassword(String currentUser, String keyChain) { def stdout = new ByteArrayOutputStream() def stderr = new ByteArrayOutputStream() exec { commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w' standardOutput = stdout errorOutput = stderr ignoreExitValue true } //noinspection GroovyAssignabilityCheck stdout.toString().trim() } def pass = getPassword("marion","android_keystore_PASSWORD") android { ndkVersion rootProject.ext.ndkVersion compileSdkVersion rootProject.ext.compileSdkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled true versionCode getVersionCodeFromNpm() versionName getVersionNameFromNpm() manifestPlaceholders = [ANDROID_GEO_API_KEY: "$System.env.ANDROID_GEO_API_KEY"] applicationId "com.example.equitazone" } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } signingConfigs { debug { storeFile file('debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } release { if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) { storeFile file(MYAPP_UPLOAD_STORE_FILE) storePassword MYAPP_UPLOAD_STORE_PASSWORD keyAlias MYAPP_UPLOAD_KEY_ALIAS keyPassword MYAPP_UPLOAD_KEY_PASSWORD } } } buildTypes { debug { signingConfig signingConfigs.debug matchingFallbacks = ['debug', 'release'] } release { signingConfig signingConfigs.release debuggable false minifyEnabled true shrinkResources true zipAlignEnabled true setProguardFiles([getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro']) ndk { debugSymbolLevel = 'FULL' } } } flavorDimensions "default" productFlavors { production { } staging { } development { } } applicationVariants.all { variant -> variant.outputs.each { output -> def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } packagingOptions { pickFirst '**/libjsc.so' pickFirst '**/libc++_shared.so' pickFirst '**/libfbjni.so' } } dependencies { implementation("com.facebook.react:react-android") implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { exclude group:'com.facebook.fbjni' } debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' } if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") } else { implementation jscFlavor } implementation platform('com.google.firebase:firebase-bom:31.2.1') implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-analytics:17.3.0' // implementation 'com.google.firebase:firebase-messaging:20.1.5' implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.google.android.gms:play-services-location:18.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0' implementation project(':react-native-vector-icons') implementation project(':react-native-push-notification') } task copyDownloadableDepsToLibs(type: Copy) { from configurations.implementation into 'libs' } apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 // supportLibVersion = "28.0.0" ndkVersion = "23.1.7779620" } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle") classpath("com.facebook.react:react-native-gradle-plugin") classpath 'com.google.gms:google-services:4.3.14' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:1.3.0" } } allprojects { repositories { mavenLocal() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } google() jcenter() maven { url 'https://www.jitpack.io' } } }
我已将此 

includeBuild('../node_modules/@react-native/gradle-plugin')

 添加到 android/settings.gradle 文件中

希望这对其他人有帮助......并且我们不会再遇到这个问题😬


0
投票
2022 年 11 月 4 日出现了一个公认的问题,React Native 团队在周末投入了大量精力来解决该问题。要解决此问题,您需要将 React Native 版本更新为已修补的版本。

欲了解更多信息,请参阅此资源:

https://github.com/facebook/react-native/issues/35210


0
投票
react-native本身存在一些问题。

对于反应本机(> = 0.63)

在 android/build.gradle 中,在 allprojects.repositories 中添加此 ExclusiveContent

allprojects { repositories { exclusiveContent { filter { includeGroup "com.facebook.react" } forRepository { maven { url "$rootDir/../node_modules/react-native/android" } } } // ... } }
对于较旧的反应原生(

< 0.63)

将其添加到 android/buld.gradle 文件的 allprojects 区域中。

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim()) allprojects { configurations.all { resolutionStrategy { // Remove this override in 0.65+, as a proper fix is included in react-native itself. force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION } }
    
© www.soinside.com 2019 - 2024. All rights reserved.