【问题标题】:IllegalArgumentException: Default constructor for class com.e.pi is not accessibleIllegalArgumentException:com.e.pi 类的默认构造函数不可访问
【发布时间】:2016-06-24 21:10:31
【问题描述】:

在调试模式和 Android Studio 中运行我的应用程序,应用程序运行良好;但是,当构建然后签署 APK 并在手机上安装时,应用程序崩溃并显示以下堆栈跟踪:

06-24 13:54:59.725 17656-17656/? E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.test, PID: 17656
   java.lang.RuntimeException: Unable to create application com.test.Utilities.TestApplication: java.lang.IllegalArgumentException: Default constructor for class com.e.pi is not accessible.
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4715)
       at android.app.ActivityThread.-wrap1(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5422)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Caused by: java.lang.IllegalArgumentException: Default constructor for class com.e.pi is not accessible.
       at com.e.mo.b(Unknown Source)
       at com.e.kh.b(Unknown Source)
       at com.e.kh.J(Unknown Source)
       at com.e.gr.a(Unknown Source)
       at com.test.Utilities.TestApplication.onCreate(Unknown Source)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4712)
       at android.app.ActivityThread.-wrap1(ActivityThread.java) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) 
       at android.os.Handler.dispatchMessage(Handler.java:102) 
       at android.os.Looper.loop(Looper.java:148) 
       at android.app.ActivityThread.main(ActivityThread.java:5422) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

我不希望删除 ProGuard 并解决问题,我们将不胜感激!

以下是申请代码:

public class TestApplication extends Application {

    public static final String TAG = "ALL";
    private static TestApplication mInstance;
    private RequestQueue mRequestQueue;

    public TestApplication()
    {
        mInstance = this;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Fabric.with(this, new Crashlytics());

        String server = "eg....";
        // Enable Local Datastore.
        Parse.enableLocalDatastore(this);
        Parse.initialize(new Parse.Configuration.Builder(this)
                .applicationId(BuildConfig.PARSE_APP_ID)
                .clientKey(BuildConfig.PARSE_CLIENT_KEY)
                .server(server)
                .build());

        // Logging set to help debug issues, remove before releasing your app.
        OneSignal.setLogLevel(OneSignal.LOG_LEVEL.DEBUG, OneSignal.LOG_LEVEL.WARN);

        OneSignal.startInit(this)
                .setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
                .setAutoPromptLocation(true)
                .init();

        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/Roboto-Regular.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build()
        );
    }

    public static synchronized TestApplication getInstance()
    {
        if(mInstance == null)
        {
            mInstance = new TestApplication();
        }
        return mInstance;
    }

    public RequestQueue getRequestQueue(Context context)
    {
        if(mRequestQueue == null)
        {
            mRequestQueue = Volley.newRequestQueue(context);
        }

        return mRequestQueue;
    }

    public <T> void addToRequestQueue(Request<T> request, String tag, Context context)
    {
        request.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
        request.setShouldCache(false);
        getRequestQueue(context).add(request);
    }

    public <T> void addToRequestQueue(Request<T> request, Context context)
    {
        request.setTag(TAG);
        getRequestQueue(context).add(request);
    }

    public void cancelPendingRequests(Object tag)
    {
        if(mRequestQueue != null)
        {
            mRequestQueue.cancelAll(tag);
        }
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
        /**
         * Callback to implement in your app to handle when a notification is opened from the Android status bar or
         * a new one comes in while the app is running.
         * This method is located in this Application class as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
         *
         * @param message        The message string the user seen/should see in the Android status bar.
         * @param additionalData The additionalData key value pair section you entered in on onesignal.com.
         * @param isActive       Was the app in the foreground when the notification was received.
         */
        @Override
        public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
            String additionalMessage = "";

            try {
                if (additionalData != null) {
                    if (additionalData.has("this")) {
                        additionalMessage = additionalData.getString("this");

                        if (additionalMessage.toString().trim().equalsIgnoreCase("x")) {
                            Intent newIntent = new Intent("com.test.push");//this has to match your intent filter
                            newIntent.putExtra("FEATURE_PUSH", "x");
                            newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(newIntent);
                        }
                        else if (additionalMessage.toString().trim().equalsIgnoreCase("y")) {
                            Intent newIntent = new Intent("com.test.push");//this has to match your intent filter
                            newIntent.putExtra("FEATURE_PUSH", "y");
                            newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(newIntent);
                        }
                    }
                }

            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }

    public ImageLoader getImageLoader() {
        return mImageLoader;
    }
}

【问题讨论】:

  • 将源代码发布到com.boulevard.Utilities.BoulevardApplication。里面有些东西是你困难的根源。
  • 在@CommonsWare 上方添加了应用程序类代码
  • 嗯...您可以尝试删除构造函数并将您的单例 mInstance=this 移动到 attachBaseContext()。如果这没有帮助——而且我不希望它有帮助——您将需要使用 ProGuard 工具对堆栈跟踪进行去混淆处理,以查看 com.e.pi 是什么。
  • 是的,我已经尝试移动构造函数并且没有任何区别。我该如何使用 ProGuard 工具来做到这一点?我不熟悉那个@CommonsWare
  • 击败我。我从一开始就没有打开混淆。

标签: android proguard


【解决方案1】:

您可以使用 support.annotation 中的 @Keep 来注释要继续使用的类或方法。

【讨论】:

    猜你喜欢
    • 2014-03-28
    • 2013-08-01
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    相关资源
    最近更新 更多