react native 随手记之打包遇到坑

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值