- android studio升级到3.0以上,执行
./gradlew assembleRelease
进行安卓打包apk时 报错:图片文件重复: Error: Duplicate resources
解决方法: 在react-native
中找到react.gradle
文件,然后再文件中doFirst
下边添加如下代码(参考issues)
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()
}
- 集成
jpush-react-native
时,安卓在debug
环境下运行正常,但是打包apk时候发生如下错误
解决方法:参考githud上的issues 可以在android
目录下的build.gradle
中添加如下代码
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27 //do this in android/app/build.gradle too
buildToolsVersion '27.0.3' //do this in android/app/build.gradle too
}
}
}
}
我的build.gradle
文件内容:
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27 //do this in android/app/build.gradle too
buildToolsVersion '27.0.3' //do this in android/app/build.gradle too
}
}
}
}
- 安卓键盘弹出时会把绝对定位的组件和键盘一块弹上去
解决方法:在AndroidManifest.xml
文件中的设置
<activity
...
android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
....
</activity>
- 安卓禁止横屏
在AndroidManifest.xml
文件中添加
<activity
...
android:screenOrientation="portrait"
....
</activity>
- 加载App中的图片资源
方法一:使用uri 必须要指定大小
<Image source={{uri: 'app_icon'}} style={{width: 40, height: 40}} />
方法二:使用require('image!x')语法,无需指定尺寸
<Image source={require('image!app_icon')} style={styles.imageStyle} />