React Native:0.62.2
1.页面上渲染很多个<TextInput></TextInput>刷新很多次时,报错:
Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.new Drawable(android.content.res.Resources)' on a null object reference
解决方案:在android/app/src/main/res/values/styles.xml 文件中加上下面的配置
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
...
<item name="android:editTextBackground">@android:color/transparent</item> //新加的
...
</style>
</resources>
2.react-native 0.62.2版本打包出错:
[drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/src/main/res/drawable-mdpi/assets_mario.png [drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/build/generated/res/react/release/drawable-mdpi-v4/assets_mario.png: Error: Duplicate resources
:app:mergeReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> [drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/src/main/res/drawable-mdpi/assets_mario.png [drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/build/generated/res/react/release/drawable-mdpi-v4/assets_mario.png: Error: Duplicate resources
* 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
解决方案:修改 /node_modules/react-native/react.gradle 文件,添加doLast
修改 /node_modules/react-native/react.gradle 文件,添加doLast
doFirst { ... }
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("ldpi").call()
moveFunc.curry("mdpi").call()
moveFunc.curry("hdpi").call()
moveFunc.curry("xhdpi").call()
moveFunc.curry("xxhdpi").call()
moveFunc.curry("xxxhdpi").call()
}
2.react-native 0.63.4:react-native run-android运行项目报错:Android project not found. Are you sure this is a React Native project?
解决方案1:找到项目根目录下,android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json .删除signing-config.json文件,再次运行即可
解决方案2:(并不是我遇到问题的解决方案,网上查到的其他可能原因)可能是react-native版本不支持当前项目的目录结构,在项目根目录执行react-native upgrade,一直输入y。然后项目的目录结构会发生改变,再次运行即可
解决方案3:可能没有解决方案1中signing-config.json文件的权限,debug和release下面都有这个文件,不清楚具体获取哪个的权限,我两个都获取了,然后再次运行也能跑
3. 有时候没有报错误信息时可以在命令窗口输入adb logcat '*:E' 查看android日志
4. 打包报错:
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
解决方案:
将这一行添加到gradle.properties中。
org.gradle.jvmargs = -Xmx4608m