2

我似乎遇到了與無數社區類似的問題;不過,我似乎沒有相同的症狀(或者至少我的Google-fu不允許我找到它)。MainActivity NoClassDefFoundError

長話短說:應用程序給我java.lang.RuntimeException: Unable to instantiate activity

根據我的理解,這隻能由不正確的加載庫順序或在AndroidManifest.xml中丟失文件引起。

這裏是我的AndroidManifest.xml

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

<uses-permission android:name="android.permission.INTERNET" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

Here is a link to my repository for those wanting to build it themselves.如果誰能給我的見解,什麼可能是錯誤的。

注:這可能是由於我的.gitignore,因爲我最後一次建造,它在我的主塔。我只在遠程計算機上遇到此問題。

TL:DR - 我的MainActivity未加載,它存在於AndriodManifest.xml中,我只使用階梯加載文件,而不是本地jar。

回答

1

你的問題可能是由不同的事情引起的,但最常見的是你有太多的庫加載,有太多的方法。

你應該能夠在你的應用multidex,這裏的指南:

multidex

的快速教程:

添加 「multiDexEnabled真正的」 你的gradle這個配置(目標SDK版本下,例如)。

添加到您的依賴關係:

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

並確保您的應用程序擴展了這個:

<application 
     ... 
     android:name="android.support.multidex.MultiDexApplication"> 
     ... 
    </application> 

無論是通過代碼或通過清單。

編輯:

測試與構建工具22的項目,SD版本22和目標22。此外,使用支持庫22 +

+0

這並沒有解決我的問題。我目前只使用我認爲是幾個圖書館的東西。 [這是我的應用程序build.gradle](https://github.com/alyons/Living-Pokedex/blob/master/Andriod/LivingPokedex/app/build.gradle);它看起來好像我加載了太多的庫? –

+0

你應該嘗試這個解決方法,我的一個朋友用來發現問題: 用構建工具22,sd版本22和目標22測試項目。另外,使用支持庫22. + – W0MP3R