2016-03-08 2 views
1

У меня есть проект, который разделен на два: модуль базового кода и специальный модуль кода приложения.Невозможно создать экземпляр службы br.com.brainweb.brainfeed.milkpoint.GCMIntentService

Я пытаюсь использовать GCMIntentService, но имея эту ошибку, когда приложение начинает работать:

03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint 

E/AndroidRuntime: FATAL EXCEPTION: main 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime: Process: br.com.brainweb.brainfeed.milkpoint, PID: 19281 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime: java.lang.RuntimeException: Unable to instantiate service br.com.brainweb.brainfeed.milkpoint.GCMIntentService: java.lang.ClassNotFoundException: Didn't find class "br.com.brainweb.brainfeed.milkpoint.GCMIntentService" on path: DexPathList[[zip file "/data/app/br.com.brainweb.brainfeed.milkpoint-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2746) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread.access$1800(ActivityThread.java:148) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:102) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:135) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:5310) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:372) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "br.com.brainweb.brainfeed.milkpoint.GCMIntentService" on path: DexPathList[[zip file "/data/app/br.com.brainweb.brainfeed.milkpoint-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2743) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread.access$1800(ActivityThread.java:148)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:102)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:135)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:5310)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:372)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)  
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime: Suppressed: java.lang.ClassNotFoundException: br.com.brainweb.brainfeed.milkpoint.GCMIntentService 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.Class.classForName(Native Method) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:   ... 11 more 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

Для описания ошибки, класс не может быть найден. Я читал, что должен быть класс GCMIntentService в том же пакете, что и приложение.

Так вот манифест моего приложения в:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="br.com.brainweb.brainfeed.milkpoint" 
    android:versionCode="5" 
    android:versionName="2.0" > 

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

    <permission 
     android:name="br.com.brainweb.brainfeed.milkpoint.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="br.com.brainweb.brainfeed.milkpoint.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:name="br.com.brainweb.brainfeed.Aplicacao" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <receiver 
      android:name="com.google.android.gcm.GCMBroadcastReceiver" 
      android:permission="com.google.android.c2dm.permission.SEND" > 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 

       <category android:name="br.com.brainweb.brainfeed.milkpoint" /> 
      </intent-filter> 
     </receiver> 

     <service android:name=".GCMIntentService" /> 

     <activity 
      android:name="br.com.brainweb.brainfeed.SplashScreen" 
      android:configChanges="orientation" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" 
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="br.com.brainweb.brainfeed.MainActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.Black.NoTitleBar" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="br.com.brainweb.brainfeed.ItemViewActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.Black.NoTitleBar" /> 
     <activity 
      android:name="br.com.brainweb.brainfeed.InfoActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:theme="@android:style/Theme.Translucent.NoTitleBar" /> 

     <service android:name="org.OpenUDID.OpenUDID_service" > 
      <intent-filter> 
       <action android:name="org.OpenUDID.GETUDID" /> 
      </intent-filter> 
     </service> 
    </application> 

</manifest> 

Там на самом деле класс GCMIntentService в пакете, и когда я ставлю точку останова в getDefaultIntentServiceClassName методе GCMBroadcastReceiver класса, строка пути к классу кажется правильной. Тем не менее я получаю эту ошибку.

Я уже пробовал много решений здесь, в Stack Overflow, но все же никто из них, похоже, не исправил это.

+0

Hey @Gustavo, возможный дублированный вопрос любезно ссылается на это [ссылка] (http://stackoverflow.com/questions/35843278/link-of-class-lcom-google-android-gms-gcm-gcmreceiver-failed) –

ответ

0

После долгого времени я наконец нашел решение.

Это как часть моей build.gradle был:

android { 
    compileSdkVersion 18 
    buildToolsVersion "21.1.2" 

    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src\\main\\java','src\\test\\java'] // Line 1 
      resources.srcDirs = ['src\\main\\java','src\\test\\java'] // Line 2 
      aidl.srcDirs = ['src\\main\\java','src\\test\\java'] 
      renderscript.srcDirs = ['src\\main\\java','src\\test\\java'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
     } 

     instrumentTest.setRoot('tests') 
    } 
} 

Мой GCMIntentService пакет был внутри src/main/java. Я удалил папки main/java и положил пакет в src.

Тогда я изменил Line 1 и Line 2, как показано выше, как это:

java.srcDirs = ['src'] // Line 1 
resources.srcDirs = ['src'] // Line 2 

И он начал работать.

Смежные вопросы