react native 打包
drawable Resource and asset merger:Duplicate resources
原因分析:
drawable 中的图片重名
解决方案:
修改react-native的react.gradle文件。在路径your project/node_modules\react-native路径下,找到doFirst,在其后添加doLast
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()
}
app.json Resource and asset merger:Duplicate resources
解决方案:
改了项目下的app.json 的名字
Android resource linking failed
原因分析:
由于工程targetSdkVersion升级到28之后,并且compileSdkVersion 也使用28之后就会出现上述报错。这是由于一些第三方库没有做及时的兼容。很多React Native工程第三库都会报这个错误解决方案:
在主工程build.gradle文件中加入下段代码
subprojects {
afterEvaluate {
project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion = 28
buildToolsVersion = "28.0.3"
}
}
}
}
Android9.0以上打包apk后http请求不到
解决方案:
android:usesCleartextTraffic=“true”
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mokrnproject">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".MainApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_logo"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:roundIcon="@mipmap/ic_logo"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:label="@string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>