Urban Airship crashes at take off. Illegal Argument Exception

╄→гoц情女王★ 提交于 2019-12-23 19:13:39

问题


My Code in Applicaion.onCreate. The app crashes at UAirship.takeoff(this,options); Please help.

public class LiveVideoApplication extends Application {
    @Override
    public void onCreate() {

        super.onCreate();

        AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);

        // Optionally, customize your config at runtime:
        //
        options.inProduction = false;
        options.developmentAppKey = "key.. ";
        options.developmentAppSecret = "secret..";

        UAirship.takeOff(this, options);
        PushManager.shared().setIntentReceiver(IntentReceiver.class);
        Logger.logLevel = Log.VERBOSE;

        //use CustomPushNotificationBuilder to specify a custom layout
        CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();

        nb.statusBarIconDrawableId = R.drawable.icon_small;//custom status bar icon
//
        nb.layout = R.layout.notification;
        nb.layoutIconDrawableId = R.drawable.icon;//custom layout icon
        nb.layoutIconId = R.id.icon;
        nb.layoutSubjectId = R.id.subject;
        nb.layoutMessageId = R.id.message;

        // customize the sound played when a push is received
        nb.soundUri = Uri.parse("android.resource://"+this.getPackageName()+"/" +R.raw.cat);

        PushManager.shared().setNotificationBuilder(nb);
        PushManager.shared().setIntentReceiver(IntentReceiver.class);

    }
}

Exception Log:

03-15 00:25:37.106: E/AndroidRuntime(2920): FATAL EXCEPTION: main
03-15 00:25:37.106: E/AndroidRuntime(2920): java.lang.RuntimeException: Unable to create application com.LiveVideoApplication: java.lang.IllegalArgumentException: Application configuration is invalid.
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3275)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.app.ActivityThread.access$2200(ActivityThread.java:117)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:969)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.os.Looper.loop(Looper.java:123)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.app.ActivityThread.main(ActivityThread.java:3683)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at java.lang.reflect.Method.invokeNative(Native Method)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at java.lang.reflect.Method.invoke(Method.java:507)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at dalvik.system.NativeStart.main(Native Method)
03-15 00:25:37.106: E/AndroidRuntime(2920): Caused by: java.lang.IllegalArgumentException: Application configuration is invalid.
03-15 00:25:37.106: E/AndroidRuntime(2920):     at com.urbanairship.UAirship.takeOff(Unknown Source)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at com.LiveVideoApplication.onCreate(LiveVideoApplication.java:27)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
03-15 00:25:37.106: E/AndroidRuntime(2920):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3272)

回答1:


I have also encountered this problem, and I resolved it. I will suggest you to make sure you have created an app on UrbanAirship with the same package of application which your application have. And also make sure your key and secret are correct.

IllegalArgumentException is thrown when the developmentAppKey and developmentAppSecret are wrong. Or key and secret are correct but your remote Urban Airship test application has a different Applicaion package set.




回答2:


One thing to note is that if you are using an airshipconfig.properties file, and you placed it at the same directory level as the project.properties file, the Urban Airship code won't be able to find it, and the call to AirshipConfigOptions.loadDefaultOptions(this) will return empty string values.

This can cause the exception you are seeing as well.

The solution in this case is to place the airshipconfig.properties file in the assets directory of your project.




回答3:


If you have checked every other suggestion, and still get an IllegalArgumentException, this exception is also thrown when the phone doesn't have any associated Google account tied to it.

If this is the case you should be able to login/associate a Google account, and then you have to restart the phone.

I would recommend wrapping the Urban Airship initialisation calls in a try catch to stop it bricking the app in this scenario! If you use error reporting it is wise to log this as a handled exception so you know if and when it is happening.



来源:https://stackoverflow.com/questions/9708885/urban-airship-crashes-at-take-off-illegal-argument-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!