2017-02-22 137 views
0

我想在我的Android應用程序中使用谷歌地圖學習的目的。我生成的API密鑰,但我得到這個錯誤。 執行失敗的任務'任務':app:transformClassesWithDexForDebug'的執行失敗。在android

:app:transformClassesWithDexForDebug'. 
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 

我如何糾正錯誤?我是新來的Android應用程序開發,所以請大家多多包涵。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.user.googlemap"> 

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 

     <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
     <meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value="my api key ,i have put it over here " /> 

     <activity 
      android:name=".MapsActivity" 
      android:label="@string/title_activity_maps"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

這裏是gradle構建文件的殭屍問。

apply { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.1" 
    defaultConfig { 
     applicationId "com.example.user.googlemap" 
     minSdkVersion 19 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     }a 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.0.1' 
    compile 'com.google.android.gms:play-services:10.0.1' 
    testCompile 'junit:junit:4.12' 
} 

進行更改後,現在我收到此錯誤。 *發生了什麼問題: 評估項目':app'時發生問題。

對於類型爲org.gradle.api.Project的項目':app'上的參數[25]找不到方法compileSdkVersion()。

  • 嘗試:
+0

在你的gradle文件中啓用multidex – zombie

+0

我應該添加build.gradle文件嗎? –

+0

@ zombie我如何在gradle文件中啓用multidex? –

回答

0

你的錯誤... DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

注意:如果方法引用的在您的應用程序數量超過65K的限制,您的應用程序可能無法編譯。您可以通過編譯你的應用程序時,僅指定特定谷歌Play服務才能緩解這個問題的API應用程序使用,而不是所有的人都

Google Play Services Setup(重點煤礦)

你確實是編譯 「所有的人」

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

您似乎只需要地圖?

然後只編譯-maps

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    testCompile 'junit:junit:4.12' 

    compile 'com.android.support:appcompat-v7:25.0.1' 
    compile 'com.google.android.gms:play-services-maps:10.2.0' // See here 
} 

(或者你可以啓用Multidex ...但是,這是矯枉過正當前問題)


然後,我不知道你做的搖籃,文件什麼,但

apply { // <-- Should be android 
    compileSdkVersion 25 

    ... 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     }a // <--- Remove this random 'a' character 
+0

請解釋爲在哪個文件我需要改變的東西? –

+0

'/ app/build.gradle'(不是說不要依賴它的那個) –

+0

我已經上傳了gradle.build。你可以在那裏做改變嗎? –

0

我今天得到了類似的問題,我改變的minSdkVersion從15到21, 後添加一行multiDexEnabled真,那麼工精細,更多信息請點擊這裏https://developer.android.com/studio/build/multidex.html,看起來升這個問題是由Multidex支持造成的。

+0

在多行添加「multiDexEnabled true」後,它可以正常工作 –

+0

您可以在我的代碼中進行更改嗎? –

+0

在gradle文件的defaultconfig部分中確保** multiDexEnabled true **和** minSdkVersion 21 **,因爲這個註釋編輯器對我來說非常有限,我不知道如何在這裏格式化文本,但我認爲你應該知道如何改變它 –

相關問題