当前位置: 首页 > 知识库问答 >
问题:

React本机Android应用程序无法生成并显示以下错误

曹沛
2023-03-14

屏幕截图真实设备

  • 一加六

我的应用程序/构建。格拉德尔

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    bundleInRelease: true,
    enableHermes: true,
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = true

def enableProguardInReleaseBuilds = true

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions { 
        checkReleaseBuilds false
    }

    defaultConfig {
        applicationId "com.****.**"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 206
        versionName "2.1"
        multiDexEnabled true
        missingDimensionStrategy 'react-native-camera', 'general'

    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {            
            // minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
            // shrinkResources true
            zipAlignEnabled true
            useProguard enableProguardInReleaseBuilds
        }

        // 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, "arm64-v8a": 3, "x86_64": 4]
                def abi = output.getFilter(OutputFile.ABI)
                if (abi != null) {  // null for the universal-debug, universal-release variants
                    output.versionCodeOverride =
                            versionCodes.get(abi) * 1048600 + defaultConfig.versionCode
                }
            }
        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'        
    }

}

dependencies {
    implementation project(':react-native-splash-screen')
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-gesture-handler')
    implementation project(':@react-native-community_netinfo')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.annotation:annotation:1.0.2'
    implementation fileTree(include: ['*.jar'], dir: 'libs')   
    implementation 'com.facebook.react:react-native:+'
    implementation 'com.android.support:multidex:1.0.1'

    // JSC from node_modules
   if (enableHermes) {
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")    
    } else {
        implementation jscFlavor
    }

    // From node_modules
    implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'
    implementation 'com.google.android.gms:play-services-identity:16.0.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    // Firebase dependencies
    implementation project(':react-native-firebase')
    implementation "com.google.android.gms:play-services-base:17.0.0"

    implementation "com.google.firebase:firebase-core:17.0.0"
    implementation "com.google.firebase:firebase-messaging:19.0.0"

    implementation project(':@mauron85_react-native-background-geolocation')
    implementation(project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
   }

}

// 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'
}

apply plugin: 'com.google.gms.google-services'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

我的顶级身材。梯度锉


buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        googlePlayServicesVersion = "11+"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.1")
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url ("$rootDir/../node_modules/react-native/android")            
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

    }
}

/*
To resolve the gradle dependency issue
*/
subprojects {
    afterEvaluate {
        project ->
            if (project.hasProperty("android")) {
            android {
            compileSdkVersion = 28
            buildToolsVersion = "28.0.3"
            }
        }
    }
}
subprojects {
  project.configurations.all {
     resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
              && !details.requested.name.contains('multidex') ) {
           details.useVersion "28.0.3"
        }
     }
  }
}

我package.json依赖

"dependencies": {
    "@mauron85/react-native-background-geolocation": "^0.6.3",
    "@react-native-community/async-storage": "^1.5.1",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-native-community/netinfo": "^3.2.1",
    "@types/react-native-vector-icons": "^6.4.2",
    "@typescript-eslint/eslint-plugin": "^2.2.0",
    "@typescript-eslint/parser": "^2.2.0",
    "buffer": "^5.2.1",
    "d3-shape": "^1.3.5",
    "deepmerge": "^3.2.0",
    "lottie-react-native": "^3.1.0",
    "moment": "^2.24.0",
    "object-path": "^0.11.4",
    "prop-types": "^15.7.2",
    "query-string": "^6.5.0",
    "react": "16.8.6",
    "react-native": "0.60.5",
    "react-native-android-location-services-dialog-box": "^2.8.2",
    "react-native-camera": "^3.0.0",
    "react-native-cli": "^2.0.1",
    "react-native-copilot": "^2.4.5",
    "react-native-datepicker": "^1.7.2",
    "react-native-device-info": "1.6.1",
    "react-native-document-picker": "^2.2.0",
    "react-native-elements": "^1.1.0",
    "react-native-exit-app": "^1.0.0",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-firebase": "~5.5.6",
    "react-native-fs": "^2.13.3",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-google-signin": "^2.0.0",
    "react-native-image-picker": "^0.28.0",
    "react-native-image-resizer": "^1.0.1",
    "react-native-image-zoom-viewer": "^2.2.25",
    "react-native-linear-gradient": "^2.5.4",
    "react-native-loader": "^1.2.1",
    "react-native-loading-spinner-overlay": "^1.0.1",
    "react-native-maps": "^0.26.1",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-permissions": "^1.1.1",
    "react-native-picker-select": "^6.1.0",
    "react-native-privacy-snapshot": "^1.0.0",
    "react-native-qrcode-scanner": "^1.2.1",
    "react-native-shared-preferences": "^1.0.0",
    "react-native-simple-toast": "0.0.8",
    "react-native-snackbar": "^2.0.2",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^9.4.0",
    "react-native-user-defaults": "^0.1.5",
    "react-native-vector-icons": "^6.6.0",
    "react-native-webview": "^5.12.1",
    "react-redux": "^5.0.6",
    "react-roka-components": "^1.0.1",
    "redux": "^3.0.0",
    "redux-devtools-extension": "^2.13.8",
    "redux-form": "^7.4.2",
    "url": "^0.11.0",
    "url-parse": "^1.4.7",
    "uuid": "^3.3.2",
    "whatwg-fetch": "^2.0.4"
  },

采取步骤解决:

尝试使用与下面链接中建议的“com.google.firebase:firebase core”和“com.google.firebase:firebase messaging”相同版本的依赖项(17.0.0)。

没有类定义错误:java。lang.NoClassDefFoundError:解析失败解析失败:Lcom/google/android/gms/common/internal/zzab;

但是gradle构建失败,出现以下错误

配置在1m0失败在项目应用程序中,一个已解决的Google Play服务库依赖依赖于另一个精确版本(例如Google Play)。"[16.0.0]",但没有解析到该版本。图书馆展示的行为将是未知的。

依赖项失败:com.google.firebase:firebase消息传递:17.0.0-

以下依赖项是项目依赖项,它们是直接的或具有可传递的依赖项,导致出现问题的工件。

--项目“应用程序”依赖于com.google.firebase:firebase消息@{17.0.0}

--项目“应用程序”依赖于com.google.firebase:firebase iid{19.0.0}

共有1个答案

颛孙越
2023-03-14

我的应用/build.gradle实现缺少以下依赖项(com.google.android.gms: play-services-place: 17.0.0)。添加这个并重建项目成功了。

 类似资料: