为什么在编译应用程序时会丢失一个类?

时间:2014-01-24 18:47:49

标签: java android maven gradle google-play-services

我正在尝试将驱动器存储实施到我的应用程序中,并且我遇到了一些让它运行的问题。它编译得很好(没有错误),但有些类文件在某处丢失了。启动我的应用程序时的错误如下:

01-24 18:40:09.747    1038-8218/? I/ActivityManager﹕ Start proc net.rymate.notes for activity net.rymate.notes/.activities.NotesListActivity: pid=6099 uid=10102 gids={50102, 3003}
01-24 18:40:09.748    1038-1103/? D/WifiStateMachine﹕ handleMessage: X
01-24 18:40:09.772    6099-6105/? D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
01-24 18:40:09.814    6099-6099/? I/dalvikvm﹕ Failed resolving Lnet/rymate/notes/storage/GoogleDriveStorage; interface 1582 'Lcom/google/android/gms/common/api/GoogleApiClient$ConnectionCallbacks;'
01-24 18:40:09.815    6099-6099/? W/dalvikvm﹕ Link of class 'Lnet/rymate/notes/storage/GoogleDriveStorage;' failed
01-24 18:40:09.815    6099-6099/? E/dalvikvm﹕ Could not find class 'net.rymate.notes.storage.GoogleDriveStorage', referenced from method net.rymate.notes.activities.NotesListActivity.onCreate
01-24 18:40:09.815    6099-6099/? W/dalvikvm﹕ VFY: unable to resolve new-instance 1949 (Lnet/rymate/notes/storage/GoogleDriveStorage;) in Lnet/rymate/notes/activities/NotesListActivity;
01-24 18:40:09.815    6099-6099/? D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0092
01-24 18:40:09.837    6099-6099/? I/dalvikvm﹕ Failed resolving Lnet/rymate/notes/storage/GoogleDriveStorage; interface 1582 'Lcom/google/android/gms/common/api/GoogleApiClient$ConnectionCallbacks;'
01-24 18:40:09.838    6099-6099/? W/dalvikvm﹕ Link of class 'Lnet/rymate/notes/storage/GoogleDriveStorage;' failed
01-24 18:40:09.839    6099-6099/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x3162 at 0x94 in Lnet/rymate/notes/activities/NotesListActivity;.onCreate
01-24 18:40:09.905    1038-8218/? D/dalvikvm﹕ GC_EXPLICIT freed 1503K, 23% free 26687K/34552K, paused 4ms+10ms, total 111ms
01-24 18:40:09.910    6099-6099/? D/AndroidRuntime﹕ Shutting down VM
01-24 18:40:09.910    6099-6099/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41616d40)
01-24 18:40:09.912    6099-6099/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: net.rymate.notes, PID: 6099
    java.lang.NoClassDefFoundError: net.rymate.notes.storage.GoogleDriveStorage
            at net.rymate.notes.activities.NotesListActivity.onCreate(NotesListActivity.java:122)
            at android.app.Activity.performCreate(Activity.java:5248)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5102)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
            at dalvik.system.NativeStart.main(Native Method)

这是问题类的源代码(我的主要活动只是创建了这个类的新实例,它没有对它做任何事情):

package net.rymate.notes.storage;

import android.app.Activity;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.drive.Drive;


/**
 * Created by Ryan on 24/01/14.
 */
public class GoogleDriveStorage implements
        ConnectionCallbacks,
        OnConnectionFailedListener {

    private static final String TAG = "GoogleDriveStorage";

    /**
     * Extra for account name.
     */
    protected static final String EXTRA_ACCOUNT_NAME = "account_name";

    /**
     * Request code for auto Google Play Services error resolution.
     */
    protected static final int REQUEST_CODE_RESOLUTION = 1;

    /**
     * Next available request code.
     */
    protected static final int NEXT_AVAILABLE_REQUEST_CODE = 2;
    private final Activity activity;

    /**
     * Google API client.
     */
    private GoogleApiClient mGoogleApiClient;

    public GoogleDriveStorage(Activity a) {
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(a.getApplication())
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        mGoogleApiClient.connect();

        this.activity = a;
    }

    /**
     * Called when {@code mGoogleApiClient} is connected.
     */
    @Override
    public void onConnected(Bundle connectionHint) {
        Log.i(TAG, "GoogleApiClient connected");
    }

    /**
     * Called when {@code mGoogleApiClient} is disconnected.
     */
    @Override
    public void onDisconnected() {
        Log.i(TAG, "GoogleApiClient disconnected");
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
        if (!result.hasResolution()) {
            // show the localized error dialog.
            GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), activity, 0).show();
            return;
        }
        try {
            result.startResolutionForResult(activity, REQUEST_CODE_RESOLUTION);
        } catch (SendIntentException e) {
            Log.e(TAG, "Exception while starting resolution activity", e);
        }
    }
}

我的build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
    mavenLocal()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
}

dependencies {
    compile project(':libs:ShowcaseView')
    // Google Play Services
    compile 'com.google.android.gms:play-services:4.1.32'
}

帮助将不胜感激!

编辑:添加manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.rymate.notes"
    android:versionCode="7"
    android:versionName="1.3" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="16" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:hardwareAccelerated="true">
        <activity android:name="net.rymate.notes.activities.NotesListActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="net.rymate.notes.activities.NoteViewActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:windowSoftInputMode="adjustResize" />
        <activity
            android:name="net.rymate.notes.activities.NoteEditActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:windowSoftInputMode="stateVisible|adjustResize" />
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

在Java Build Path下的项目属性中 - &gt;订单和导出确保选中“Android私有库”和“Android依赖项”。然后清洁并再试一次。

Order and Export