1

我的應用程序工作正常,但問題來了,這是與multidex的android有關。我搜索了這個問題,並根據android.developers指南進行了必要的更新。但是,我一直在與同樣的問題鬥爭數小時。應用不同的解決方案,但仍然存在相同的問題。一個gradle構建立即花費11-12分鐘,並且爲了測試一個解決方案,我必須等待11-12分鐘,這真的會讓我失望。我在分享我的Gradle和清單文件。請幫助解決這個問題。無法更新multidex行爲

的build.gradle文件

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.0" 

    defaultConfig { 
     applicationId "com.example.mudasir.login" 
     minSdkVersion 16 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    packagingOptions{ 
     exclude'META-INF/NOTICE.txt' 
     exclude'META-INF/NOTICE' 
     exclude'META-INF/notice.txt' 
     exclude'META-INF/LICENSE.txt' 
     exclude'META-INF/LICENSE' 
     exclude'META-INF/license.txt' 

    } 
    dexOptions{ 
     preDexLibraries = false 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    //compile 'com.android.support:appcompat-v7:24.2.0' 
    compile 'com.android.support:design:24.2.0' 
    compile 'com.android.support:support-v4:24.2.0' 
    compile 'com.google.android.gms:play-services:9.4.0' 

} 

清單文件:

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

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.CALL_PHONE" /> 

    <!-- 
     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"> 
     android:name="android.support.multidex.MultiDexApplication"> 
     <activity 
      android:name=".SignUpActivity" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme.NoActionBar" /> 
     <activity 
      android:name=".MainScreenActivity" 
      android:label="@string/title_activity_main_screen_activity" 
      android:theme="@style/AppTheme.NoActionBar"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".SignInActivity" 
      android:label="@string/title_activity_signin_" 
      android:theme="@style/AppTheme.NoActionBar" /> 
     <activity 
      android:name=".sidemenu_Activity" 
      android:theme="@style/AppTheme.NoActionBar"> 


     </activity> 

     <!-- 
      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="@string/google_maps_key" /> 

     <activity 
      android:name=".MapsActivity" 
      android:label="@string/title_activity_maps"> 
     </activity> 
    </application> 

</manifest> 

回答

1

附加按照您的gradle這個文件

dependencies { 
    compile 'com.android.support:multidex:1.0.0' 
} 

依賴欲瞭解更多信息,請訪問:https://developer.android.com/studio/build/multidex.html

+0

讓我查一下..這是唯一的問題..? –

+0

是的,你已經指定multidexEnabled真正的和更新的應用程序標記 – abhishesh

+0

好吧,讓我試試..它將需要10 miuntes gradle構建來檢查一個解決方案.. :( –

2

你有這部分添加到您的build.gradle

dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
} 

真正的問題是您正在使用:

compile 'com.android.support:support-v4:24.2.0' 
compile 'com.google.android.gms:play-services:9.4.0' 

不應該永遠使用compile 'com.google.android.gms:play-services:9.4.0'爲包括每Google Play服務庫 - 僅使用APIs you need

同爲V4支持庫已分裂成幾個smaller modules.