Build.grad 在 Android 9 上模拟时不会加载 'index.js' bundle



我创建了我的应用程序,每个用户都有一个登录功能,可以拥有自己的个人资料。当我在 androids 版本 6、7.1、8.1 中测试模拟该应用程序时,它会正常安装,当它到达登录部分时,应用程序会识别用户/密码并登录。

但是当我在Android 9上模拟时,发生了一些错误。输入用户/密码后,它不会加载下一页,我意识到我的"index.js"捆绑包在启动 react-native run-android 命令时没有加载。

我该如何解决?

Windows 10,React Native 最新版本,MongoDB。

登录代码:

loginUser() {
    login(this.state)
      .then(response => {
        if (response) {
          const aux = response.data;
          aux.jwt = response.token;
          this.props.updateALL(aux);
          Actions.main();
        }
      })
      .catch(error => {
        this.setState({ alertMessage: error.message, showIcon: true });
      });   }

Package.JSON

{
  "name": "ifun",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "aws-sdk": "^2.395.0",
    "axios": "^0.18.0",
    "date-diff": "^0.2.1",
    "fuctbase64": "^1.4.0",
    "google-map-react": "^1.1.2",
    "install": "^0.12.2",
    "native-base": "^2.8.1",
    "react": "^16.6.3",
    "react-dom": "^16.8.1",
    "react-native": "^0.55.4",
    "react-native-aws3": "0.0.8",
    "react-native-carousel-view": "^0.5.1",
    "react-native-elements": "^1.1.0",
    "react-native-geolocation-service": "^2.0.0",
    "react-native-i18n": "^2.0.15",
    "react-native-image-picker": "^0.27.2",
    "react-native-lightbox": "^0.8.0",
    "react-native-mime-types": "^2.2.1",
    "react-native-modal": "^7.0.2",
    "react-native-modal-datetime-picker": "^6.0.0",
    "react-native-router-flux": "^3.45.0",
    "react-redux": "^5.1.1",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "babel-jest": "23.4.0",
    "babel-preset-react-native": "4.0.0",
    "eslint-config-rallycoding": "^3.2.0",
    "jest": "23.4.1",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

Build.Gradle App

apply plugin: "com.android.application"
import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.ifun"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        multiDexEnabled true 
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}
dependencies {
    compile project(':react-native-image-picker')
    compile project(':react-native-i18n')
    compile project(':react-native-geolocation-service')
    implementation project(':react-native-i18n')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-geolocation-service')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:28.0.0"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

当我在Android 9上模拟时,发生了一些错误。输入用户/密码后,它不会加载下一页,我意识到我的"index.js"捆绑包在启动 react-native run-android 命令时没有加载。

我该如何解决?

验证现有应用在新版平台上是否正常工作。此步骤不使用新的 API 或更改应用程序的targetSdkVersion ,但可能需要进行细微更改。

你能试试低TargetSdkVersion吗?

如果此问题已解决,请参阅此处以获取更多信息。

最新更新