任务':app:transformClassesWithMultidexlistForProdRelease'的执行失败

时间:2019-02-26 10:24:41

标签: android react-native-android dex multidex

我在构建应用程序时遇到相同的错误 任务':app:transformClassesWithMultidexlistForProdRelease'的执行失败

> com.android.build.api.transform.TransformException:生成主dex列表时出错。

我的 build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
        }
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    minSdkVersion = 16
    compileSdkVersion = 27
    targetSdkVersion = 27
    buildToolsVersion = "27.0.3"
    supportLibVersion = "27.1.0"
    googlePlayServicesVersion = "15.0.1"
    gradle3EXPERIMENTAL = "yes"
}

subprojects{
    if(name.equals('react-native-google-analytics-bridge')){
        project.ext.'googlePlayServicesVersion'='12.0.1'
    }
} 

我的 app / build.gradle

android {
    dexOptions {
        javaMaxHeapSize "4g"
    }
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.smarttimer"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 17
        versionName "3.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        multiDexEnabled=true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    aaptOptions {  
        additionalParameters "--no-version-vectors"  
    } 
    flavorDimensions "version"
    productFlavors {
        uat {
            resValue "string", "app_name", "Uat Timer"
            resValue "string", "content_provider", "com.smarttimer.uat.provider"
            resValue "string", "content_authority", "com.smarttimer.uat.provider"
        }
        prod {
            resValue "string", "app_name", "Smart Timer"
            resValue "string", "content_provider", "com.smarttimer.provider"
            resValue "string", "content_authority", "com.smarttimer.provider"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            storeFile file(MY_AWESOME_PROJECT_RELEASE_STORE_FILE)
            storePassword MY_AWESOME_PROJECT_RELEASE_STORE_PASSWORD
            keyAlias MY_AWESOME_PROJECT_RELEASE_KEY_ALIAS
            keyPassword MY_AWESOME_PROJECT_RELEASE_KEY_PASSWORD
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // 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
            }
        }
    }
    android.applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "com.utopiatech.smart-timer.apk"
        }
    }
    project.ext {
        googlePlayServicesVersion = "15.0.0"
    }
}
    dependencies {
        implementation project(':react-native-config')
        implementation project(':react-native-mauron85-background-geolocation')
        implementation project(':react-native-linear-gradient')
        implementation project(':react-native-google-analytics-bridge')
        implementation project(':react-native-firebase')
        implementation project(':react-native-device-info')
        implementation project(':react-native-camera')
        implementation project(':react-native-android-location-services-dialog-box')
        implementation fileTree(dir: "libs", include: ["*.jar"])
        implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
        implementation "com.facebook.react:react-native:0.56.0" // From node_modules
        implementation "com.google.android.gms:play-services-base:15.0.1"
        implementation "com.google.firebase:firebase-core:16.0.3"
        implementation "com.google.android.gms:play-services-analytics:15.0.2"
        implementation "com.google.firebase:firebase-messaging:17.3.0"
        implementation "com.android.support:multidex:1.0.3"
        implementation "com.android.support:design:27.1.0"
    }

Package.json如下

{
"name": "SmartTimer",
"version": "0.0.1",
"private": true,
"scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
},
"rnpm": {
    "assets": [
        "./assets/fonts/Lato",
        "./assets/fonts/NotoSans",
        "./assets/fonts/NunitoSans"
    ]
},
"dependencies": {
    "axios": "^0.18.0",
    "find-cache-dir": "^2.0.0",
    "firebase": "^5.4.2",
    "firebase-messaging": "^1.0.6",
    "lodash": "^4.17.5",
    "moment": "^2.21.0",
    "moment-timezone": "^0.5.14",
    "native-base": "^2.3.10",
    "react": "^16.4.2",
    "react-moment": "^0.7.0",
    "react-native": "^0.56.0",
    "react-native-android-location-services-dialog-box": "^2.4.4",
    "react-native-camera": "^1.1.1",
    "react-native-config": "^0.11.5",
    "react-native-device-info": "^0.21.5",
    "react-native-firebase": "^4.3.8",
    "react-native-fontawesome": "^5.7.0",
    "react-native-google-analytics-bridge": "^5.6.3",
    "react-native-keyboard-aware-scroll-view": "^0.6.0",
    "react-native-linear-gradient": "^2.4.0",
    "react-native-loader": "^1.2.1",
    "react-native-mauron85-background-geolocation": "^0.5.0-alpha.40",
    "react-native-modal": "^6.2.0",
    "react-native-modal-dropdown": "^0.6.2",
    "react-native-phone-input": "^0.2.1",
    "react-native-pull-to-refresh": "^2.1.3",
    "react-native-router-flux": "^4.0.0-beta.28",
    "react-native-simple-popover": "^2.1.0",
    "react-native-vector-icons": "^5.0.0",
    "socket.io-client": "^2.0.4"
},
"devDependencies": {
    "babel-jest": "^23.0.0-alpha.0",
    "babel-preset-react-native": "^5.0.2",
    "jest": "^22.4.2",
    "metro": "^0.45.0",
    "metro-core": "^0.45.0",
    "react-test-renderer": "^16.3.0-alpha.2"
},
"jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
        "/node_modules/(?!native-base)/"
    ]
}
}

我尝试使用Predex = true,但是即使一个小时后构建仍未完成。尝试过Git-hub解决方案和stackoverflow解决方案。我还尝试了许多配置更改。其中一些是上述配置的一部分。我不太确定,但我认为问题是由于版本不兼容所致。有人请仔细检查是否有必要进行一些更改以提高兼容性(如果有必要并适用)。

0 个答案:

没有答案