添加GMS到Android应用程序的位置服务现在它崩溃

时间:2013-11-29 04:11:45

标签: android android-studio google-play-services android-location android-gradle

我刚刚将GMS添加到我的应用程序以使用LocationClient,现在我的应用程序在启动时崩溃了。看起来我的主要活动无法再找到处理位置逻辑的服务。

我将以下行添加到我的gradle依赖项中,以便拉入gms。

compile 'com.google.android.gms:play-services:4.0.30'

这是我得到的错误。

28 22:10:39.761    2885-2885/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.nathan.allgood, PID: 2885
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/myname/appname/services/ActivityService;

在我的清单中也有这个:

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

任何想法?

谢谢, 森

编辑:添加了发生错误的LogCat和方法

    /**
     * Bind this Activity to MyService
     */
    private void doBindService() {
        getActivity().bindService(new Intent(getActivity(), ActivityService.class), mConnection, Context.BIND_AUTO_CREATE);
        mIsBound = true;
    }

11-28 22:53:59.502    2278-2278/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myname.appname, PID: 2278
java.lang.NoClassDefFoundError: com.myname.appname.services.ActivityService
        at com.myname.appname.Activity1$OneFragment.automaticBind(Activity1.java:119)
        at com.myname.appname.Activity1$OneFragment.onResume(Activity1.java:105)
        at android.app.Fragment.performResume(Fragment.java:1743)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1044)
        at android.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1863)
        at android.app.Activity.performResume(Activity.java:5332)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2779)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2818)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2251)
        at android.app.ActivityThread.access$700(ActivityThread.java:145)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1407)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5062)
        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 dalvik.system.NativeStart.main(Native Method)
11-28 23:33:12.336    6335-6335/com.myname.appname E/dalvikvm﹕ Could not find class    'com.myname.appname.services.ActivityService', referenced from method   com.myname.appname.Activity1$OneFragment.doBindService
11-28 23:33:12.386    6335-6335/com.myname.appname E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myname.appname, PID: 6335
java.lang.NoClassDefFoundError: com.myname.appname.services.ActivityService
        at com.myname.appname.Activity1$OneFragment.automaticBind(Activity1.java:119)
        at com.myname.appname.Activity1$OneFragment.onResume(Activity1.java:105)
        at android.app.Fragment.performResume(Fragment.java:1743)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1044)
        at android.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1863)
        at android.app.Activity.performResume(Activity.java:5332)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2779)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2818)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2251)
        at android.app.ActivityThread.access$700(ActivityThread.java:145)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1407)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5062)
        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 dalvik.system.NativeStart.main(Native Method)

编辑2: 我还应该提到我正在使用Android Studio

解!!! 编辑3:
根据另一个stackoverflow帖子的一些建议,我做了一个 gradlew清理然后gradlew构建,这似乎解决了问题!

1 个答案:

答案 0 :(得分:0)

因为您尚未发布代码,请在logcat中查找“由...引起”。告诉我为什么你使用AsyncTask来获取你的位置?