2017-10-16 6 views
7

作成中のアプリで問題が発生しています。基本的には、アプリケーションを初めて開こうとするとクラッシュし、その後は正常に終了します。混乱する部分は、Google Playからアプリをダウンロードするときにのみ発生します。 Androidスタジオからアプリをスマートフォンに直接ロードするとエラーは発生しません。プロダクションリリースでのアプリの読み込み時にRuntimeExceptionが発生する

java.lang.RuntimeException: 
    at android.app.ActivityThread.handleReceiver (ActivityThread.java:3290) 
    at android.app.ActivityThread.-wrap20 (ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1715) 
    at android.os.Handler.dispatchMessage (Handler.java:102) 
    at android.os.Looper.loop (Looper.java:154) 
    at android.app.ActivityThread.main (ActivityThread.java:6682) 
    at java.lang.reflect.Method.invoke (Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1520) 
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410) 
Caused by: java.lang.ClassNotFoundException: 
    at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56) 
    at java.lang.ClassLoader.loadClass (ClassLoader.java:380) 
    at java.lang.ClassLoader.loadClass (ClassLoader.java:312) 
    at android.app.ActivityThread.handleReceiver (ActivityThread.java:3285) 

この問題を調査した後、私は人々がデバイスのキャッシュをクリアすると言います。これで問題は解決しましたが、それはアプリを拭き取り、それ以降は正常に動作します。最初のインストールはまだクラッシュします。これは複数のデバイスで発生しましたが、デバッグ中は再現できません。私の唯一の考えは、setContentView()を呼び出した直後にonCreate()にこのコードがあることです。

Intent intent = new Intent(this, NotificationListener.class); 
startService(intent); 
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); 

NotificationListener.classはNotificationListenerServiceを継承します。最初の打ち上げを除いてすべてが素晴らしいです。

UPDATE

は、ここで私はAndroidManifestでサービスを設定する方法である:ここでは

<service android:name=".NotificationListener" 
    android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> 
    <intent-filter> 
     <action android:name="android.service.notification.NotificationListenerService" /> 
    </intent-filter> 
</service> 

は私NotificationListenerServiceの簡易版である:ここで

public class NotificationListener extends NotificationListenerService 
{ 
    private IBinder mBinder = new LocalBinder(); 

    @Override 
    public void onNotificationPosted(StatusBarNotification sbn) 
    { 
     super.onNotificationPosted(sbn); 

     // custom code 
    } 

    @Override 
    public void onNotificationRemoved(StatusBarNotification sbn) 
    { 
     super.onNotificationRemoved(sbn); 
    } 

    @Override 
    public IBinder onBind(Intent intent) 
    { 
     if (SERVICE_INTERFACE.equals(intent.getAction())) 
      return super.onBind(intent); 
     else return mBinder; 
    } 

    public class LocalBinder extends Binder 
    { 
     public NotificationListener getService() 
     { 
      return NotificationListener.this; 
     } 
    } 
} 

はのためServiceConnectionですバインダー:

private ServiceConnection serviceConnection = new ServiceConnection() 
{ 
    @Override 
    public void onServiceConnected(ComponentName componentName, IBinder iBinder) 
    { 
     NotificationListener.LocalBinder localBinder = (NotificationListener.LocalBinder) iBinder; 
     notificationListener = localBinder.getService(); 
     bound = true; 

     // code to call custom function in NotificationListener class 
    } 

    @Override 
    public void onServiceDisconnected(ComponentName componentName) 
    { 
     notificationListener = null; 
     bound = false; 
    } 
}; 

私はすべてのバインディングコードを削除してサービスを開始すれば、すべてが必要なように実行されるため、これはサービスのバインドに関する問題であることがわかります。このエラーが発生するのはバインドコードを追加するときだけです。

+0

もし私がプロガードなしでapkファイルを作成しようとしていますか? – kimkevin

+1

@KimKevinその場合、私はそれを削除し、私のアプリのベータ版をアップロードし、まだ起動時に同じエラーが発生しました – saboehnke

+0

はい、それはfalseとして設定されているか、ClassNotFoundExceptionが発生したため...登録しましたか? NotificationListenerServiceからAndroidManiへfest.xml? – kimkevin

答えて

1

サービスを再起動して再度バインドする必要はありません。以下のコードを削除した後、署名apkファイルを作成してください。

Intent intent = new Intent(this, NotificationListener.class); 
startService(intent); 

[EDIT]

私はそれはProGuardの難読化だと思うので、あなたのProGuardのファイルに次のコードを追加してください。

# Base Android exclusions, required for proper function of various components 
-keep public class * extends android.app.Activity 
-keep public class * extends android.app.Application 
-keep public class * extends android.app.Service 
-keep public class * extends android.content.BroadcastReceiver 
-keep public class * extends android.content.ContentProvider 
-keep public class * extends android.preference.Preference 
-keep public class * extends android.support.v4.app.Fragment 
-keep public class * extends android.app.Fragment 
+0

私は先に進み、bindService()がそれを処理する必要があるので、startService()呼び出しを削除しました。それはまだクラッシュします。エラーが変更されたかどうかを確認したいが、何らかの理由でベータ版のクラッシュが発生しない。 – saboehnke

+0

ええ、startService()を削除しても同じエラーが表示されます。 – saboehnke

+0

私はproguardファイルを扱う経験がありませんので、私はproguard-android.txt-2.3.3ファイルと私のaapt_rules.txtファイルの両方に追加しました。それはまだクラッシュします。 – saboehnke

0

この問題は一般的にproguardのために発生します。プロジェクトにproguardを追加すると、このような機能が停止します。

だけ追加することにより、proguard-rules.proファイルにあなたのサービス・モジュールを追加しよう

-keepクラス{パッケージ名} {サービスモジュール名} ** {*。。。 }

例:> -keep class com.demo.service。** {*; }

これは、proguardのすべてのサービス許可を追加します。

+0

プロガードが問題の原因になっている場合は、プロガードを取り外すことはできますか? – saboehnke

+0

すべてのものはそこに独自の賛否両論を持って、Proguardも持っています。それはあなたにも良いセキュリティと他の多くの機能を提供します。 私の意見は、このファイルを完全に削除するのではなく、proguard-rules.proファイルに追加することです。 –

0

ClassNotFoundExceptionここに空のメッセージがあります。dalvik.system.BaseDexClassLoaderのソースコードを見ると、見つからない場合は指定されたクラスの名前を持つClassNotFoundExceptionがスローされるため、空のクラス名をどこかで(すなわち、ActivityThread::handleReceiverによって処理されるメッセージに)渡しています。 ブランチにこのhandleReceiverコールを委任するブランチトレースを提供できれば大いに役立ちます。

関連する問題