我正在尝试用我开发的应用程序找出崩溃发生的原因。
获取Firebase实例时应用程序崩溃,只有从MDM应用程序中心下载的应用程序才会发生这种情况,通过直接闪存或从playstore下载的模拟器和设备启动工作正常,从客户端从MDM应用程序中心下载的应用程序会发生此异常
客户端在包装MDX工具之前已经包含了senderid和API密钥。
以下是日志:
Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String android.content.pm.PackageItemInfo.name' on a null object reference
at com.citrix.mdx.f.a.a(Unknown Source)
at com.citrix.mdx.f.a.a(Unknown Source)
at com.citrix.MAM.Android.ManagedApp.l.a(Unknown Source)
at com.citrix.MAM.Android.ManagedApp.l.a(Unknown Source)
at com.citrix.MAM.Android.ManagedApp.l.invoke(Unknown Source)
at com.citrix.mdx.e.d.b(Unknown Source)
at citrix.android.content.pm.PackageManager.queryIntentServices_aroundBody5$advice(Unknown Source)
at citrix.android.content.pm.PackageManager.queryIntentServices(Unknown Source)
at com.google.firebase.iid.zzl.zzdf(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceIdService.zzem(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.<init>(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at citrix.android.content.pm.PackageManager.queryIntentServices_aroundBody5$advice(Unknown Source)
at citrix.android.content.pm.PackageManager.queryIntentServices(Unknown Source)
at com.google.firebase.iid.zzl.zzdf(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceIdService.zzem(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.<init>(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)异常在代码中的这一行抛出:
case R.id.register_btn:
if (validateInput()) {
showProgress("Loading...");
String android_id = Settings.Secure.getString(this.getContentResolver(),
Settings.Secure.ANDROID_ID);
//here is where am getting null pointer exception only with wrapped apk
final String firebaseId = FirebaseInstanceId.getInstance().getToken();
String myVersion = android.os.Build.VERSION.RELEASE;
final LoginData signUpData = new LoginData(userId_et.getText().toString().trim(), password_et.getText().toString(), "ANDROID " + myVersion, phone_et.getText().toString(), firebaseId);
apiService.userLogin(signUpData).enqueue(new Callback<LoginResult>() {
@Override
public void onResponse(Call<LoginResult> call, Response<LoginResult> response) {
dismissProgress();
}下面是我的gradle级别代码:
dependencies {
compile 'com.google.android.gms:play-services:11.4.2'
compile 'com.google.firebase:firebase-messaging:11.4.2'
compile 'com.google.firebase:firebase-crash:11.4.2'
}
apply plugin: 'com.google.gms.google-services' 项目级Gradle文件:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.google.firebase:firebase-plugins:1.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
} 清单中的Firebase服务注册
<!-- [START firebase_service] -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<service
android:name=".service.MyFirebaseMessagingService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
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="com.fc.debug" />
</intent-filter>
</receiver>
<!-- [END firebase_service] -->
<!-- [START firebase_iid_service] -->
<service android:name=".service.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_iid_service] -->MyFirebaseInstanceIDService类
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
*/
// [START refresh_token]
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
// String refreshedToken = FirebaseInstanceId.getInstance().getToken();
String refreshedToken = " ";
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
sendRegistrationToServer(refreshedToken);
}
// [END refresh_token]
/**
* Persist token to third-party servers.
* <p>
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
}MyApplication类:
public class MyApplication extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
@Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
}发布于 2018-05-31 23:23:05
尝试更新项目级别grandle,如下所示:
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.1'
classpath 'com.google.firebase:firebase-plugins:1.1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
} 还有grandle level:
dependencies {
implementation 'com.google.android.gms:play-services:15.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-crash:16.0.0'
}
apply plugin: 'com.google.gms.google-services' https://stackoverflow.com/questions/49451522
复制相似问题