Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Publish an Android App Publishing on Google Play Uploading an APK

TJ Rogers
TJ Rogers
8,758 Points

Android Beta app crashes when opening from Playstore (but works otherwise)

I just recently finished an app I'm working on, and published it as a beta version to the Play Store. Before sending this to my beta testers, I sent a link to myself just to see if it works. When I clicked the link and installed the app from the Play Store it appears to have loaded to my device just fine. But then when I open the app, it crashes before it even opens. I get an "Unfortunately, App Name has stopped" message.

Just to double check and make certain I didn't mess anything up last minute before publishing, I uninstalled and ran the app from my device using Android Studio and it runs just fine.

The only thing I can think may be causing this are a few things I did before building the APK.

First, in my build.gradle file I inserted "optimize" to this line of code:

    buildTypes {
            release {
                runProguard true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }

Then in the proguard-rules.pro I added the following:

    -assumenosideeffects class android.util.Log {
        public static boolean isLoggable(java.lang.String, int);
        public static int v(...);
        public static int i(...);
        public static int w(...);
        public static int d(...);
        public static int e(...);
    }
    -ignorewarnings

I added these per Ben's instructions in the video tutorial to remove Logs - although the ignorewarnings line I added on my own.

I added the "ignorewarnings" line because on building the APK, I got 78 yellow warnings, all of which had to do with Facebook. But I have no facebook integration and never even attempted to write any code to integrate facebook. So I assumed that adding the ignorewarnings line wouldn't impede the function of the app. Was I mistaken?

So that's my problem. Any ideas what the issue may be?

EDIT:

Below is my Stack Trace for the crash:

java.lang.RuntimeException: Unable to create application com.offyear.www.offyear.Application: java.lang.IllegalArgumentException: Default constructor for class com.a.lb is not accessible.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4447)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Default constructor for class com.a.lb is not accessible.
at com.a.gy.c(Unknown Source)
at com.a.gy.C(Unknown Source)
at com.a.ed.a(Unknown Source)
at com.offyear.www.offyear.Application.onCreate(Unknown Source)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
... 10 more

1 Answer

Notice in your /app/build.gradle file, the ProGuard properties are in the buildTypes.release. When you upload the app to Play, it's required to run as a release build. By default, when you are running from Android Studio, you will be running the app as debug mode. To make bug fixing easier for you, you can run release mode in Android Studio. The option for this is called "Build Variants" and is typically found in the lower-left corner. Once you open that window, click on "debug" and change it to "release".

In the stacktrace, the actual location of the bug is obfuscated. Wouldn't it be great if you knew exactly what class was the problem? It's possible, and you can find that information in a blog post I wrote: http://blog.simplyadvanced.net/android-how-to-decode-proguards-obfuscated-code-from-stack-trace/

And, to take a wild guess on the root cause of the error, does your app by any chance use Fragment? When the Android system restores a Fragment, it wants to use a no-argument constructor...

As a sidenote, I would recommend fixing all the warning. They can be cause for a lot of trouble and it's very likely that others have also already ran into that same issue.