美文网首页
记录react-native开发中的一些问题

记录react-native开发中的一些问题

作者: Michael1 | 来源:发表于2018-11-24 17:17 被阅读41次
    1. 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()
                }
    
    1. 集成jpush-react-native时,安卓在debug环境下运行正常,但是打包apk时候发生如下错误 A5D2AEBB07892832D0AA8C21B7428155.jpg
      解决方法:参考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
                }
            }
        }
    }
    
    1. 安卓键盘弹出时会把绝对定位的组件和键盘一块弹上去
      解决方法:在AndroidManifest.xml 文件中的设置
    <activity
      ...
      android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
      ....
    </activity>
    
    1. 安卓禁止横屏
      AndroidManifest.xml 文件中添加
    <activity
      ...
      android:screenOrientation="portrait"
      ....
    </activity>
    
    1. 加载App中的图片资源
      方法一:使用uri 必须要指定大小
    <Image source={{uri: 'app_icon'}} style={{width: 40, height: 40}} />
    

    方法二:使用require('image!x')语法,无需指定尺寸

    <Image source={require('image!app_icon')} style={styles.imageStyle} />
    

    相关文章

      网友评论

          本文标题:记录react-native开发中的一些问题

          本文链接:https://www.haomeiwen.com/subject/injyqqtx.html