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