为什么我仍然得到java

为什么我仍然得到java

本文介绍了为什么我仍然得到java.lang.NoClassDefFoundError的:android.support.v7.appcompat.R $ ATTR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在开发一个俗气的应用程序,使岗位训练自己的机器人之前,我在我的公司的真正的应用程序项目。我快到多数民众赞成给我虽然非常困难的时期的错误。

So I'm developing a cheesy app to make posts to train myself in android before I work on my firm's real app project. I'm running into a bug that's giving me a very difficult time though.

我得到的库依赖关系列表,我是用了,有我的build.gradle文件设置为加载它们在它同步很好,所以我认为它这样做的权利尽我所知:

I was given a list of library dependencies that I was to use, and have my build.gradle file set up to load them in. It syncs fine, so I assume it's done right to the best of my knowledge:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.squareup.okhttp:okhttp:2.3.0'
    compile 'com.squareup.retrofit:retrofit:1.7.0'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.dagger:dagger:1.2.2'
    compile 'com.squareup.dagger:dagger-compiler:1.2.2'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:recyclerview-v7:22.1.1'
    compile 'com.squareup:otto:1.3.7'
    compile 'com.path:android-priority-jobqueue:1.1.2'
    compile 'io.realm:realm-android:0.80.1'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:appcompat-v7:22.1.1'
}

和我其实已经安装了Android的支持库和资源库:

And I have actually installed the android support library AND repository:

然而,我仍然尝试启动应用程序并获得以下堆栈跟踪:

And yet I still try and launch the app and get the following stack trace:

java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$attr
        at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:286)
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
        at com.anglersatalas.twitstagram.MainActivity.onCreate(MainActivity.java:23)
        at android.app.Activity.performCreate(Activity.java:5451)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
        at android.app.ActivityThread.access$900(ActivityThread.java:169)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5487)
        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:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)

在其他地方对堆栈溢出我见过有解决方案添加appcompat V7库,因为他们说的做就Android的网站,我已经证明了我之前所做的那样。我想不通,我的生活为什么仍然发生。纵观堆栈跟踪,它打破了我的MainActivity处的setContentView()方法:

Everywhere else on Stack Overflow I've seen has the solution as adding the appcompat v7 libraries as they say to do on the android website, which I've demonstrated I've done above. I can't figure out for the life of me why this is still happening. Looking at the stack trace, it breaks in my MainActivity at the setContentView() method:

package com.anglersatalas.twitstagram;

import android.os.Bundle;
import com.anglersatalas.twitstagram.R;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.anglersatalas.twitstagram.api.PostService;
import com.anglersatalas.twitstagram.models.Post;

import java.util.List;

import retrofit.RestAdapter;


public class MainActivity extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.anglersatalas.twitstagram.R.layout.activity_main);

        TextView tv =  (TextView)findViewById(com.anglersatalas.twitstagram.R.id.textView);

        RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint("10.0.0.248/testserver/backend/web")
                .build();

        PostService service = adapter.create(PostService.class);
        List<Post> list = service.getPosts();
        String str = "";
        for(Post p : list){
            str += String.format("%s\n", p);
        }
        tv.setText(str);

    }

    ...

}

通过单击的类文件被调用抛出异常的方法,它表明,它无法找到'android.support.v7.appcompat.R;

Clicking through to the class file that is calling the method that throws the exception, it shows that it can't find 'android.support.v7.appcompat.R;':

我的同事和我都处于亏损状态。任何建议,如何解决这个问题?

My coworkers and I are at a loss. Any suggestions as to how to remedy this?

推荐答案

我刚刚花了几个小时与此相同的问题,我能够把它解决了...

I just spent hours with this same issue, and I was able to get it resolved...

原来我是在DEX限制,我确实有multiDexEnabled在defaultConfig在我build.gradle文件真实,但它看起来像我错过了一些其他的东西了pre 5.0设备。

It turns out I was over the dex limit, I did have multiDexEnabled true in my build.gradle file under defaultConfig, but it looks like I was missing a few other things for pre 5.0 devices..

defaultConfig {
...
        multiDexEnabled true
... }

我先检查了我的方法算这一点:https://github.com/mihaip/dex-method-counts

我是在67952方法...

I was at 67952 methods...

然后我更新了我的build.gradle添加multidex支持

I then updated my build.gradle to add multidex support

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

然后我更新了我的应用程序(我们已经有我们自己)从MultiDexApplication延长

I then updated my Application (we already have our own) to extend from MultiDexApplication

package com.me.myapp
...
public class Application extends MultiDexApplication {}

下面是从我用正确实现multidex文档中的两个环节:https://developer.android.com/tools/building/multidex.htmlhttps://developer.android.com/reference/android/support/multidex/MultiDexApplication.html

Here were the two links from the documentation I used to correctly implement multidex:https://developer.android.com/tools/building/multidex.htmlhttps://developer.android.com/reference/android/support/multidex/MultiDexApplication.html

请确保在清单指向您的自定义应用程序multidex您的应用程序

Make sure your application in the manifest points to your custom multidex application

<application
...
android:name="com.me.myapp.Application" />

这篇关于为什么我仍然得到java.lang.NoClassDefFoundError的:android.support.v7.appcompat.R $ ATTR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:11