我创建了一个带有react-native的新项目,其中包含几个软件包(react-native-camera,react-native-device-info,react-native-elements,react-native-geocoder,react-native-qrcode-scanner) ,react-native-vector-icons,react-navigation),但我无法弄清为什么它不生成。我执行以下命令来生成APK:
gradlew clean
gradlew assembleRelease
输出为:
com.android.ide.common.process.ProcessException:无法执行aapt
如果我删除了react-native-device-info软件包,则下一个已安装的软件包react-native-camera会出现错误。
如果我在grade.properties中将android.enableAapt2 = true设置为true(禁用aapt2会引发以上错误),则会出现以下错误:
D:\WorkingCopy\Apps\CpVehicle\src\android\app\build\intermediates\res\merged\release\drawable-hdpi\node_modules_reactnavigation_src_views_assets_backicon.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
error: failed parsing overlays.
我的build.gradle文件是这样的:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "$rootDir/../node_modules/react-native/android" }
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
mavenCentral()
google()
}
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion '27.1.1'
}
}
}
}
gradle-wrapper.properties:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
项目刚开始时,我没有错误地构建了APK。
如果我尝试使用Android Studio进行构建,则可以正常运行,但可以从出现崩溃的设备中打开该应用。在Play商店控制台中,我收到此错误:
FATAL EXCEPTION: Thread-3
Process: com.cpvehicle, PID: 8053
java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
谢谢。
答案 0 :(得分:4)
我发现了此解决方案或更有效的解决方法:
在gradle.properties上禁用aapt2
android.enableAapt2 = false
build.gradle的内部子项目中插入以下内容:
afterEvaluate { 项目->如果(project.hasProperty(“ android”)){ android { 编译版本26 } } }