2015-12-11 36 views
17

Aplikacja, nad którą pracuję (kod bazowy nie został napisany przeze mnie, zawierający pewną liczbę dużych bibliotek, których nie można usunąć). W ostatnim uruchomieniu zaczęto odpowiadać komunikatem:Dlaczego korzystanie z multiDexEnabled (true) pozwala aplikacji na budowanie, ale stale się zawiesza?

Dzieje się tak tylko wtedy, gdy aplikacja próbuje zbudować, gdy używana jest strzałka uruchamiania, pomyślnie buduje się podczas wywoływania "przebuduj" lub "wyczyść".

Rozwiązanie zawarte w wierszu jest użycie multiDexEnabled prawdziwe (multiDex documentation here.)

Używanie tego udało mi się dostać do budynku zarówno „run” strzałką i „odbudować”. Jednak aplikacja zbudowany i prowadzony na awarie telefonów treścią następujący komunikat:

12-11 16:17:16.963 28868-28868/? D/dalvikvm: Late-enabling CheckJNI 
12-11 16:17:17.023 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10471 (common_google_play_services_updating_text) in Lcom/google/android/gms/R$string; 
12-11 16:17:17.023 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0021 
12-11 16:17:17.023 28868-28868/com.myname.myappcoop I/dalvikvm: DexOpt: unable to optimize static field ref 0x28e8 at 0x2e in Lcom/google/android/gms/common/GoogleApiAvailability;.zza 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10465 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string; 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0012 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10462 (common_google_play_services_notification_ticker) in Lcom/google/android/gms/R$string; 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0013 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10437 (common_ic_googleplayservices) in Lcom/google/android/gms/R$drawable; 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0039 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10462 (common_google_play_services_notification_ticker) in Lcom/google/android/gms/R$string; 
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0099 
12-11 16:17:17.043 28868-28868/com.myname.myappcoop I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzj 
12-11 16:17:17.043 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve virtual method 616: Landroid/content/pm/PackageManager;.getPackageInstaller()Landroid/content/pm/PackageInstaller; 
12-11 16:17:17.043 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b 
12-11 16:17:17.043 28868-28868/com.myname.myappcoop I/dalvikvm: DexOpt: unable to optimize static field ref 0x28c4 at 0x6c in Lcom/google/android/gms/common/GooglePlayServicesUtil;.zza 
12-11 16:17:17.043 28868-28868/com.myname.myappcoop I/dalvikvm: DexOpt: unable to optimize static field ref 0x28e9 at 0x6e in Lcom/google/android/gms/common/GooglePlayServicesUtil;.zza 
12-11 16:17:17.083 28868-28907/com.myname.myappcoop I/GMPM: App measurement is starting up 
12-11 16:17:17.083 28868-28907/com.myname.myappcoop E/GMPM: getGoogleAppId failed with status: 10 
12-11 16:17:17.083 28868-28907/com.myname.myappcoop E/GMPM: Uploading is not possible. App measurement disabled 
12-11 16:17:17.113 28868-28868/com.myname.myappcoop D/dalvikvm: GC_FOR_ALLOC freed 358K, 3% free 16887K/17276K, paused 11ms, total 12ms 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8714 (static_string) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x000b 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8710 (static_string2) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x000e 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8711 (static_string3) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0011 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8716 (static_string4) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0014 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8717 (static_string5) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0017 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8721 (static_string6) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x001a 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8720 (static_string7) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x001d 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8719 (static_string8) in Lcom/myname/display/R$string; 
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0020 
12-11 16:17:17.143 28868-28868/com.myname.myappcoop D/MAIN: Context 1 : [email protected] 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop E/dalvikvm: Could not find class 'com.myname.myapp.view.FalseActionBar$1', referenced from method com.myname.myapp.view.FalseActionBar.initializeView 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve new-instance 3015 (Lcom/myname/myapp/view/FalseActionBar$1;) in Lcom/myname/myapp/view/FalseActionBar; 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x22 at 0x002a 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10366 ($SwitchMap$com$myname$myapp$view$FalseActionBar$TitleMode) in Lcom/myname/myapp/view/FalseActionBar$3; 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x62 at 0x0005 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: DexOpt: unable to opt direct call 0x5db9 at 0x2c in Lcom/myname/myapp/view/FalseActionBar;.initializeView 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: DexOpt: unable to opt direct call 0x5dba at 0x46 in Lcom/myname/myapp/view/FalseActionBar;.initializeView 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/AndroidRuntime: Shutting down VM 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4162fba8) 
12-11 16:17:17.163 28868-28868/com.myname.myappcoop E/AndroidRuntime: FATAL EXCEPTION: main 
          Process: com.myname.myappcoop, PID: 28868 
          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myname.myappcoop/com.myname.myapp.MainActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class com.myname.myapp.view.FalseActionBar 
           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 
           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
           at android.app.ActivityThread.access$800(ActivityThread.java:135) 
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
           at android.os.Handler.dispatchMessage(Handler.java:102) 
           at android.os.Looper.loop(Looper.java:136) 
           at android.app.ActivityThread.main(ActivityThread.java:5001) 
           at java.lang.reflect.Method.invokeNative(Native Method) 
           at java.lang.reflect.Method.invoke(Method.java:515) 
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
           at dalvik.system.NativeStart.main(Native Method) 
          Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class com.myname.myapp.view.FalseActionBar 
           at android.view.LayoutInflater.createView(LayoutInflater.java:620) 
           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
           at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
           at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
           at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
           at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 
           at android.app.Activity.setContentView(Activity.java:1929) 
           at com.myname.myapp.MainActivity.onCreate(MainActivity.java:96) 
           at android.app.Activity.performCreate(Activity.java:5231) 
           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)  
           at android.app.ActivityThread.access$800(ActivityThread.java:135)  
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)  
           at android.os.Handler.dispatchMessage(Handler.java:102)  
           at android.os.Looper.loop(Looper.java:136)  
           at android.app.ActivityThread.main(ActivityThread.java:5001)  
           at java.lang.reflect.Method.invokeNative(Native Method)  
           at java.lang.reflect.Method.invoke(Method.java:515)  
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)  
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)  
           at dalvik.system.NativeStart.main(Native Method)  
          Caused by: java.lang.reflect.InvocationTargetException 
           at java.lang.reflect.Constructor.constructNative(Native Method) 
           at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
           at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)  
           at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  
           at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  
           at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  
           at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  
           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)  
           at android.app.Activity.setContentView(Activity.java:1929)  
           at com.myname.myapp.MainActivity.onCreate(MainActivity.java:96)  
           at android.app.Activity.performCreate(Activity.java:5231)  
           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  
           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)  
           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)  
           at android.app.ActivityThread.access$800(ActivityThread.java:135)  
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)  
           at android.os.Handler.dispatchMessage(Handler.java:102)  
           at android.os.Looper.loop(Looper.java:136)  
           at android.app.ActivityThread.main(ActivityThread.java:5001)  
           at java.lang.reflect.Method.invokeNative(Native Method)  
           at java.lang.reflect.Method.invoke(Method.java:515)  
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)  
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)  
           at dalvik.system.NativeStart.main(Native Method)  
          Caused by: java.lang.NoClassDefFoundError: com.myname.myapp.view.FalseActionBar$1 
           at com.myname.myapp.view.FalseActionBar.initializeView(FalseActionBar.java:61) 
           at com.myname.myapp.view.FalseActionBar.<init>(FalseActionBar.java:46) 
           at java.lang.reflect.Constructor.constructNative(Native Method)  
           at java.lang.reflect.Constructor.newInstance(Constructor.java:423)  
           at android.view.LayoutInflater.createView(LayoutInflater.java:594)  
           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)  
           at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  
           at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  
           at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  
           at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  
           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)  
           at android.app.Activity.setContentView(Activity.java:1929)  
           at com.myname.myapp.MainActivity.onCreate(MainActivity.java:96)  
           at android.app.Activity.performCreate(Activity.java:5231)  
           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  
           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)  
           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)  
           at android.app.ActivityThread.access$800(ActivityThread.java:135)  
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)  
           at android.os.Handler.dispatchMessage(Handler.java:102)  
           at android.os.Looper.loop(Looper.java:136)  
           at android.app.ActivityThread.main(ActivityThread.java:5001)  
           at java.lang.reflect.Method.invokeNative(Native Method)  
           at java.lang.reflect.Method.invoke(Method.java:515)  
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)  
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)  
           at dalvik.system.NativeStart.main(Native Method)  
12-11 16:17:46.173 28868-28868/? I/Process: Sending signal. PID: 28868 SIG: 9 

WHERE kod jest upaść (spowodowane przez: java.lang.NoClassDefFoundError: com.myname.myapp.view.FalseActionBar $ 1) jest wtedy, gdy zgłaszany jest słuchacz. Pierwotnie był w innej klasie rozszerzającej się na detektorze kliknięć, więc wprowadziłem go do kodu, ale to nie pomogło.

title.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View v) { 
      switch (mode) { 
       case NONE: 
        //Nothing! 
        break; 

       case BACK: 
        if(delegate != null){ 
         delegate.goBack(backLocation); 
        } 
        break; 

       case HOME: 
        if(delegate != null){ 
         delegate.goHome(); 
        } 
        break; 
      } 
     } 

I początkowo myślałem że problem był z inflater chociaż teraz jestem pewny, to musi być z wykorzystaniem multiDex.

Co robi multiDex powodując awarię inflacji?

+0

Jeśli naprawdę chcesz mieć pewność, że wróciłeś do poprzedniego stanu, poza uruchomieniem 'git reset --hard', nie zapomnij uruchomić' git clean -fxd', ponieważ spowoduje to usunięcie wszystkich plików, które nie są śledzone przez git – gturri

+0

@gturri - dzięki, po powrocie w pełni udało mi się dostać do pracy. Pomogło mi to zrozumieć, skąd bierze się problem. Otrzymuję komunikat o błędzie podczas próby uruchomienia aplikacji, w której plik java.exe kończy pracę z kodem zakończenia 2. Naprawiono to, gdy używam multiDexEnabled, ale wydaje się, że przyczyną awarii aplikacji jest błąd. – Luke

+0

Mam zaktualizowane pytanie, aby nadać kontekst komunikatowi o błędzie w świetle nowych informacji – Luke

Odpowiedz

7

trzeba zrobić następujące rzeczy

  1. w kompilacji.Gradle dodać

    dexOptions { 
        javaMaxHeapSize "4g" 
    } 
    
  2. umożliwić multidex

    defaultConfig { 
        multiDexEnabled true 
    } 
    
  3. utworzyć plik wystaje z MultiDexApplication następująco

    public class App extends MultiDexApplication { 
    
        @Override 
        protected void attachBaseContext(Context base) { 
         super.attachBaseContext(base); 
         MultiDex.install(this); 
        } 
    } 
    

    i uczynić tę klasę 'APP' jako klasy aplikacji w oczywisty jak poniżej -

    <application 
        android:name=".activity.App" 
    
3

Wystarczy dodać

android:name="android.support.multidex.MultiDexApplication" 

w AndroidManifest.xml w tagu application XM jako nieruchomości.

To rozwiąże wszystkie problemy.

1

Nadzieję używasz android studio. Spróbuj dodać tę linię do pliku zbyt Gradle i przetestuj samo

dexOptions { 
     javaMaxHeapSize "4g" 
    }