Android Studio React Native 构建失败
Posted
技术标签:
【中文标题】Android Studio React Native 构建失败【英文标题】:Android Studio React Native Build fails 【发布时间】:2020-08-12 05:10:32 【问题描述】:我在工作场所的家中开发了我正在开发的项目,并想在我的机器上运行它。
我得到了很多我修复的错误,但有些我不知道如何解决。也许你们知道解决办法。
\android\app\build\intermediates\external_file_lib_dex_archives\debug\out
从 AS 构建项目时会生成此输出。
我读到解决方法是将这个:android.enableBuildCache=false
添加到 gradle.properties 但是当我这样做时,我得到了这个错误,这使得 0 意义 tbh。
:Cannot parse project property android.enableBuildCache='false ' of type 'class java.lang.String' as boolean. Expected 'true' or 'false'.
编辑:好的,在 false 之后有一个空格,因此出现了第二个错误,但即使纠正了,我也得到了第一个错误。
从 vsCode 运行它给了我:Execution failed for task ':app:processDebugResources'.
EDIT2:AS 中的最新错误:
> Task :app:mergeExtDexDebug
java.nio.file.NoSuchFileException: C:\Users\Faded\Desktop\Development\React Native\FitnessApp\FitnessApp\android\app\build\intermediates\external_file_lib_dex_archives\debug\out
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsDirectoryStream.<init>(WindowsDirectoryStream.java:80)
at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(WindowsFileSystemProvider.java:522)
at java.nio.file.Files.newDirectoryStream(Files.java:457)
at java.nio.file.Files.list(Files.java:3451)
at com.android.build.gradle.internal.tasks.DexMergingParams.getAllDexFiles(DexMergingTask.kt:502)
at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:423)
at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:335)
at org.gradle.workers.internal.AdapterWorkAction.execute(AdapterWorkAction.java:50)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:50)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:65)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1$1.create(NoIsolationWorkerFactory.java:61)
at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:98)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:61)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:53)
at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:217)
at org.gradle.workers.internal.DefaultWorkerExecutor$3.call(DefaultWorkerExecutor.java:212)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:748)
> Task :app:transformClassesWithDexBuilderForDebug
> Task :app:validateSigningDebug UP-TO-DATE
> Task :app:signingConfigWriterDebug
> Task :app:mergeDebugJavaResource
> Task :app:mergeExtDexDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> java.nio.file.NoSuchFileException: C:\Users\Faded\Desktop\Development\React Native\FitnessApp\FitnessApp\android\app\build\intermediates\external_file_lib_dex_archives\debug\out
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 19s
150 actionable tasks: 147 executed, 3 up-to-date
【问题讨论】:
【参考方案1】:尝试从 projectname/android - 文件夹中删除 .gradle 文件夹并重建。帮我解决了。
【讨论】:
谢谢!这是为我做的 错误:无法找到或加载主类 org.gradle.wrapper.GradleWrapperMain【参考方案2】:我之前也遇到过类似的错误。作为解决方案的研究结果
在android/app/build.gradle
文件multiDexEnabled true
中
android
defaultConfig
...
targetSdkVersion 28
multiDexEnabled true // here
...
【讨论】:
兄弟,你是它在我的模拟器上实际旋转的人,但如果我然后去 npm run android 我得到这个错误:任务':app:processDebugResources'的执行失败。【参考方案3】:正如Murat Kızılöz 建议的那样,您可以通过在android/app/build.gradle
文件中添加multiDexEnabled true
来解决此问题。
这是因为Android系统有64K的参考限制
In Android, the compilers convert your source code into DEX files. This DEX file
contains the compiled code used to run the app. But there is a limitation with the
DEX file. The DEX file limits the total number of methods that can be referenced
within a single DEX file to 64K i.e. 65,536 methods. So, you cant use more than
64K methods in a particular DEX file. These 64K methods include Android framework
methods, library methods, and methods in our code also. This limit of 64K is
referred to as the "64K reference limit".
因此,如果我们的应用超过 65,536 个方法,我们将遇到构建错误,表明我们的应用已达到 Android 构建架构的限制。
要解决这个问题,您可以在 app build.gradle 文件中手动启用它
您可以在Android Multidex阅读更多相关信息
【讨论】:
【参考方案4】:在您的项目根目录中尝试此命令:
cd android && rm -rf .gradle && rm -rf .idea
然后
./gradlew clean
然后再次构建,就像一个魅力。
【讨论】:
以上是关于Android Studio React Native 构建失败的主要内容,如果未能解决你的问题,请参考以下文章
如何将 React-Native 项目集成到 Android-Studio?
React Native Android入门实战及深入源码分析系列——React Native源码编译
[react-native]Getting Started for Android on Windows
React-Native 开发 android & ios App,共享一份代码