1

我一直在使用react native並在按照說明添加adjust sdk之後,無法編譯android端的項目。 我有問題是在無法使用Google Services Analytics編譯反應原生項目

compile 'com.google.android.gms:play-services-analytics:10.0.1' 

如果該行不放在那裏,然後將其編譯的沒有問題的build.gradle關於這條線,但它在那裏,這是行不通的與此錯誤(第一夫婦的上下文行):

:app:transformClassesWithDexForRelease 

Running dex as a separate process. 

To run dex in process, the Gradle daemon needs a larger heap. 
It currently has 1024 MB. 
For faster builds, increase the maximum heap size for the Gradle daemon to at least 1536 MB. 
To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties. 
For more information see https://docs.gradle.org/current/userguide/build_environment.html 


AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zzf;","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\ncom.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zzf;\n\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:591)\n\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:546)\n\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:528)\n\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)\n\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)\n\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)\n\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)\n\tat com.android.dx.command.dexer.Main.run(Main.java:277)\n\tat com.android.dx.command.dexer.Main.main(Main.java:245)\n\tat com.android.dx.command.Main.main(Main.java:106)\n","tool":"Dex"} 

:app:transformClassesWithDexForRelease FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':app:transformClassesWithDexForRelease'. 
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 36.108 secs 

核心例外似乎是:

Error:Error converting bytecode to dex: 
    Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zzf; 

我使用這個庫是的,因爲這些指令的唯一原因: https://github.com/adjust/react_native_sdk#google-play-services

任何幫助將不勝感激!

FYI:我已經嘗試了一堆的解決方案,例如在圖書館努力force=true從只是隨機的谷歌搜索

我的gradle構建和的package.json其餘上下文

沒有運氣

build.grade

apply plugin: "com.android.application" 

import com.android.build.OutputFile 

/** 
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 
* and bundleReleaseJsAndAssets). 
* These basically call `react-native bundle` with the correct arguments during the Android build 
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 
* bundle directly from the development server. Below you can see all the possible configurations 
* and their defaults. If you decide to add a configuration block, make sure to add it before the 
* `apply from: "../../node_modules/react-native/react.gradle"` line. 
* 
* project.ext.react = [ 
* // the name of the generated asset file containing your JS bundle 
* bundleAssetName: "index.android.bundle", 
* 
* // the entry file for bundle generation 
* entryFile: "index.android.js", 
* 
* // whether to bundle JS and assets in debug mode 
* bundleInDebug: false, 
* 
* // whether to bundle JS and assets in release mode 
* bundleInRelease: true, 
* 
* // whether to bundle JS and assets in another build variant (if configured). 
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 
* // The configuration property can be in the following formats 
* //   'bundleIn${productFlavor}${buildType}' 
* //   'bundleIn${buildType}' 
* // bundleInFreeDebug: true, 
* // bundleInPaidRelease: true, 
* // bundleInBeta: true, 
* 
* // the root of your project, i.e. where "package.json" lives 
* root: "../../", 
* 
* // where to put the JS bundle asset in debug mode 
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 
* 
* // where to put the JS bundle asset in release mode 
* jsBundleDirRelease: "$buildDir/intermediates/assets/release", 
* 
* // where to put drawable resources/React Native assets, e.g. the ones you use via 
* // require('./image.png')), in debug mode 
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 
* 
* // where to put drawable resources/React Native assets, e.g. the ones you use via 
* // require('./image.png')), in release mode 
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 
* 
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means 
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 
* // date; if you have any other folders that you want to ignore for performance reasons (gradle 
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 
* // for example, you might want to remove it from here. 
* inputExcludes: ["android/**", "ios/**"], 
* 
* // override which node gets called and with what additional arguments 
* nodeExecutableAndArgs: ["node"] 
* 
* // supply additional arguments to the packager 
* extraPackagerArgs: [] 
* ] 
*/ 

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

/** 
* Set this to true to create two separate APKs instead of one: 
* - An APK that only works on ARM devices 
* - An APK that only works on x86 devices 
* The advantage is the size of the APK is reduced by about 4MB. 
* Upload all the APKs to the Play Store and people will download 
* the correct one based on the CPU architecture of their device. 
*/ 
def enableSeparateBuildPerCPUArchitecture = false 

/** 
* Run Proguard to shrink the Java bytecode in release builds. 
*/ 
def enableProguardInReleaseBuilds = false 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.1" 

    defaultConfig { 
     applicationId "example.app" 
     minSdkVersion 16 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
     ndk { 
      abiFilters "armeabi-v7a", "x86" 
     } 
     //multiDexEnabled true 
    } 
    //dexOptions { 
    // preDexLibraries = false 
    //} 
    signingConfigs { 
     release { 
      storeFile file(MYAPP_RELEASE_STORE_FILE) 
      storePassword MYAPP_RELEASE_STORE_PASSWORD 
      keyAlias MYAPP_RELEASE_KEY_ALIAS 
      keyPassword MYAPP_RELEASE_KEY_PASSWORD 
     } 
    } 
    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" 
      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 
      } 
     } 
    } 
} 

repositories { 
    mavenCentral() 
    maven { url "https://jitpack.io" } 
} 

dependencies { 
    compile project(':react-native-adjust') 
    compile project(':react-native-version-number') 
    compile project(':react-native-fcm') 
    compile project(':react-native-fbsdk') 
    compile project(':react-native-dialogs') 
    compile project(':react-native-image-picker') 
    compile project(':react-native-camera') 
    compile project(':realm') 
    compile project(':react-native-vector-icons') 
    compile 'com.google.firebase:firebase-core:10.0.1' //this decides your firebase SDK version 
    compile 'com.facebook.android:facebook-android-sdk:[4,5)' 
    compile fileTree(dir: "libs", include: ["*.jar"]) 
    compile "com.android.support:appcompat-v7:23.0.1" 
    compile "com.facebook.react:react-native:+" // From node_modules 
    compile 'com.google.android.gms:play-services-analytics:10.0.1' 
} 

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

和的package.json:

{ 
    "name": "example", 
    "version": "0.5.0", 
    "private": true, 
    "scripts": { 
    "start": "node node_modules/react-native/local-cli/cli.js start", 
    "android": "react-native run-android", 
    "rev": "adb reverse tcp:8081 tcp:8081", 
    "ios": "react-native run-ios --simulator='iPhone 7'", 
    "release:android": "cd android && ./gradlew assembleRelease && cd ..", 
    "cdapk": "cd android/app/build/outputs/apk", 
    "lint": "eslint .", 
    "test": "jest" 
    }, 
    "dependencies": { 
    "base-64": "^0.1.0", 
    "chroma-js": "^1.2.1", 
    "eslint-plugin-react": "^6.3.0", 
    "lodash": "^4.16.4", 
    "moment": "^2.16.0", 
    "react": "~15.4.0-rc.4", 
    "react-native": "0.38.0", 
    "react-native-adjust": "^4.11.3", 
    "react-native-animatable": "^0.6.1", 
    "react-native-camera": "^0.4.1", 
    "react-native-dialogs": "0.0.19", 
    "react-native-fbsdk": "^0.4.0", 
    "react-native-fcm": "^2.5.5", 
    "react-native-image-picker": "^0.23.0", 
    "react-native-keyboard-aware-scroll-view": "^0.2.8", 
    "react-native-mimetype": "0.0.7", 
    "react-native-modal-picker": "0.0.16", 
    "react-native-navbar": "^1.5.4", 
    "react-native-popup-menu": "^0.7.5", 
    "react-native-router-flux": "^3.35.0", 
    "react-native-scrollable-tab-view": "0.6.0", 
    "react-native-search-bar": "^2.16.0", 
    "react-native-swiper": "^1.5.4", 
    "react-native-tabs": "^1.0.9", 
    "react-native-vector-icons": "^3.0.0", 
    "react-native-version-number": "^0.1.2", 
    "react-redux": "^4.4.5", 
    "realm": "^0.14.3", 
    "redux": "^3.6.0", 
    "redux-logger": "^2.6.1", 
    "redux-saga": "^0.12.1", 
    "z-schema": "^3.18.0" 
    }, 
    "devDependencies": { 
    "babel-jest": "17.0.2", 
    "babel-preset-react-native": "1.9.0", 
    "eslint": "^3.6.1", 
    "eslint-plugin-react": "^6.3.0", 
    "jest": "17.0.3", 
    "jest-react-native": "17.0.3", 
    "react-test-renderer": "~15.4.0-rc.4", 
    "redux-devtools": "^3.3.1", 
    "remote-redux-devtools": "^0.5.1" 
    }, 
    "jest": { 
    "preset": "react-native" 
    } 
} 

回答

0

調整React本機SDK需要此依賴關係才能閱讀Google Play服務廣告標識符。也許您的項目包含一些插件,這些插件已包含Google Play服務庫的這部分內容,因此在您自己的環境中添加此依賴項可能會導致對其進行多次引用。

你可以嘗試跳過添加這種依賴併爲您在沙箱中的情況下跟蹤會話或事件時,相應調整SDK詳細日誌,你看到的是正在使用的會話/事件包發送名爲gps_adid該參數,那麼這意味着你的應用程序已經包含谷歌Play的一部分是調整SDK需要,以閱讀谷歌播放服務廣告識別碼,並在這種情況下,沒有必要爲你增添服務項目庫:

compile 'com.google.android.gms:play-services-analytics:10.0.1'