【问题标题】:Noclassdeffounderror - Can't find v7 support (android studio)Noclassdeffounderror - 找不到 v7 支持(android 工作室)
【发布时间】:2015-10-04 18:30:18
【问题描述】:

所以我尝试使用 GCM 构建应用程序。我为此打开了 2 个模块。一个后端(使用 appengine 和一个常规模块的 GCM 消息传递 - 名称是“app”(常规模块)和“后端”)。

我收到了这个问题,但我想不出它的独奏。

当应用程序启动时,我收到以下错误:

10-04 18:24:16.391 18920-18920/com.example.daniel.testing6 E/AndroidRuntime: 致命异常: main java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$attr 在 android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:289) 在 android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246) 在 android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 在 com.example.daniel.testing6.MainActivity.onCreate(MainActivity.java:14) 在 android.app.Activity.performCreate(Activity.java:5104) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 在 android.app.ActivityThread.access$600(ActivityThread.java:141) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 在 android.os.Handler.dispatchMessage(Handler.java:99) 在 android.os.Looper.loop(Looper.java:137) 在 android.app.ActivityThread.main(ActivityThread.java:5041) 在 java.lang.reflect.Method.invokeNative(Native Method) 在 java.lang.reflect.Method.invoke(Method.java:511) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 在 dalvik.system.NativeStart.main(Native Method)

我的项目名称是 Testing6 及其 gradle: // 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

my app module gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"

    defaultConfig {
        applicationId "com.example.daniel.testing6"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true // i added it because i got different problem
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile project(path: ':backend', configuration: 'android-endpoints')
}

and my backend module:

// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
    }
}

repositories {
    jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
    compile 'com.google.appengine:appengine-endpoints:1.9.18'
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.18'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'com.googlecode.objectify:objectify:4.0b3'
    compile 'com.ganyo:gcm-server:1.0.2'
}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
}

public class MainActivity extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }


}

有人知道怎么解决吗???

【问题讨论】:

    标签: java android google-app-engine gradle


    【解决方案1】:

    问题解决了!

    好的,我做了以下操作:

    清单:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.daniel.testing6" >
    
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    
        <permission
            android:name="com.example.gcm.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
    
        <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
    
        <application
            android:name="com.example.daniel.testing6.Application"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".Main2Activity"
                android:label="@string/title_activity_main2"
                android:theme="@style/AppTheme.NoActionBar" >
            </activity>
        </application>
    
    </manifest>
    

    好的,为了摆脱错误,我去了我的模块应用程序的 gradle: 所以它看起来像这样:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "23.0.0 rc2"
    
        defaultConfig {
            applicationId "com.example.daniel.testing6"
            minSdkVersion 15
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile project(path: ':backend', configuration: 'android-endpoints')
        //
        compile 'com.android.support:appcompat-v7:22.2.1'
        compile 'com.google.android.gms:play-services:8.1.0'
        compile 'com.android.support:multidex:1.0.0'
        compile 'com.android.support:design:22.2.1'
    }
    

    接下来我创建了一个应用程序如下:

    package com.example.daniel.testing6;
    
    import android.content.Context;
    import android.support.multidex.MultiDex;
    import android.support.multidex.MultiDexApplication;
    
    /**
     * Created by Daniel on 05-Oct-15.
     */
    public class Application extends MultiDexApplication {
        @Override
        protected void attachBaseContext(Context base) {
            super.attachBaseContext(base);
            MultiDex.install(this);
        }
    }
    

    和一个主要的活动通常:

    package com.example.daniel.testing6;
    
    import android.content.Context;
    import android.content.Intent;
    import android.os.PersistableBundle;
    import android.support.multidex.MultiDex;
    import android.support.multidex.MultiDexApplication;
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.Menu;
    import android.view.MenuItem;
    
    
    public class MainActivity extends ActionBarActivity{
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            startActivity(new Intent(this, Main2Activity.class));
        }
    
    }
    

    manifast 调用上传其所有数据的应用程序,然后在数据到达我们的范围后移动到 Activity :)

    【讨论】:

      【解决方案2】:

      您还必须:

      Include `compile 'com.android.support:multidex:1.0.0'` in your dependencies
      

      更多详情请见https://developer.android.com/tools/building/multidex.html

      还有你的Application class extend MultiDexApplication 而不仅仅是Application。或者,您可以在您的应用程序的attachBaseContext() 中调用MultiDex.install()

      【讨论】:

      • 请查看此链接stackoverflow.com/questions/26609734/…>
      • 现在得到了这个问题:10-04 21:12:32.665 6335-6335/com.example.daniel.testing6 E/AndroidRuntime: FATAL EXCEPTION: main 10-04 21:12:32.665 6335- 6335/com.example.daniel.testing6 E/AndroidRuntime:java.lang.RuntimeException:无法实例化活动 ComponentInfo{com.example.daniel.testing6/com.example.daniel.testing6.MainActivity}:java.lang.ClassCastException: com.example.daniel.testing6.MainActivity 无法转换为 android.app.Activity
      • 我不明白该怎么做……当它被调用时我不明白,这东西没有视图
      • 它没有 oncreate 方法,你能给我解释一下它是什么,以及我如何看待它像一个活动???
      【解决方案3】:

      在 SDK 管理器中安装/更新 Android Support Library 和 Android Support Repository 将修复此类错误

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多