Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Publish an Android App Publishing on Google Play Building a Release-Ready APK

Having problems Generate Signed APK

I did exactly what he said and I have no errors in my program however when I try to do the final step I received an error

In the message Gradle Build it says

Execution failed for task 'app:proguardRelease'.

proguard.ParseException: Expecting opening "{" at Log in line 18 of file'C:\Users\ Slim Jim\AndriodStudioProjects\FunFacts\app\proguard-rules.pro'

can someone help me find this problem

Harry James
Harry James
14,780 Points

Hey Amon!

Could you please provide the contents of your proguard-rules.pro file here so that I could take a look?

Thanks in advance!

1 Answer

jenyufu
jenyufu
3,311 Points

I have the same problem, did you solve it yet?

Harry James
Harry James
14,780 Points

Hey jenyufu!

Could you also provide the contents of your proguard-rules.pro file here?

I'll take a look at the file tomorrow and help you out :)

jenyufu
jenyufu
3,311 Points

Hi Harry, I am trying to publish another android project i made (not fun facts). The problem is I can't find it. This is the only proguard related file I can find:

Proguard.txt

# Fabric Proguard Config
-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {*;}

However in the build.gradle file: my proguard is enabled (I thought gradle would automatically create ) and I have cleanproject/build the file with no errors.

Here is my build.gradle file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 11
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.stackkedteam.feedshare"
        minSdkVersion 11
        targetSdkVersion 15
    }

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

dependencies {
    //compile 'com.android.support:support-v4:18.0.0'
    compile 'com.android.support:support-v4:21.0.+'
    compile files('libs/Parse-1.4.3.jar')
    compile 'com.parse.bolts:bolts-android:1.+'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.3@aar') {
        transitive = true;
    }
}

So what do I do now? Do I make a proguard-rules file and how would I do that?

jenyufu
jenyufu
3,311 Points

Harry James, can you please, pretty please look at the files today, because my deadline is today and I'm trying to get it done.

Harry James
Harry James
14,780 Points

Hey jenyufu!

Very sorry I couldn't back to you yesterday - I didn't see your message due to timezone differences.

Anyhow, that .txt Proguard looks as expected to me.


Can you please open your project in Finder or Windows Explorer by right-clicking on the app directory in Android Studio:

and then check to see if a proguard-rules.pro file exists in that folder? If it does, please provide its contents (Or the file itself using a service like Google Drive if you don't have software to open it) here. Alternatively, if you need the problem fixed fast, you can try deleting the file but PLEASE TAKE A BACKUP FIRST - your project may need the rules (Most do not but it's still possible).

If the file does not exist, please go ahead and give me the full error log for your specific issue so that I can help out further.


Speak to you soon :)

jenyufu
jenyufu
3,311 Points

So there was no proguard file so I went a head and created my own:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

#-dontwarn com.parse.FacebookAuthenticationProvider
#-dontwarn com.parse.**
#-dontwarn io.fabric.**
#-dontwarn bolts.**
#-dontwarn com.google.android.gms.**

-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn io.fabric.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {
    native <methods>;
}

#http://stackoverflow.com/questions/24765588/proguard-cannot-find-referenced-libraries

Good news: it worked and generated the apk. and I submitted it to the PlayStore

Bad news when I download it from the PlayStore the app just opens and crashes. Here is the log:

http://pastebin.com/xtXB9abX

^If you could help, I would be so very grateful.

Harry James
Harry James
14,780 Points

Hey again jenyufu!

It looks like this is definitely happening at runtime with signed APK's, which is where proguard kicks in. Disabling it would fix the issue as a temporary fix for you. Proguard seems to be deleting important code that makes our app work.

The problem with using proguard is that is obfuscates our code, so that we can't see where the problem lies exactly.

Could you try using a proguard-rules.pro file rather than a proguard-rules.txt file in your build.gradle to see if that makes any difference?:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                                                                     ^

So, to clarify, the first bit is .txt and the second is .pro (You can copy/paste this line).

If the specific class is causing issues for some reason, we can force proguard to ignore only that class - this means the class will not be optimized or obfuscated.

You can do that with this line of code:

-keep class com.stackkedteam.feedshare.DispatchActivity {*;}

Also, you can read how to deobfuscate stack traces so that you can find the error which should make it easier to track down such issues.


Let me know how it goes!

jenyufu
jenyufu
3,311 Points

So I tried it and published it on PlayStore, it still doesn't work. I am actually using a proguard-rules.pro file (not a proguard-rules.txt) file. The log for the crash is the same as before:

java.lang.AbstractMethodError: abstract method "void android.app.Application$ActivityLifecycleCallbacks.onActivityCreated(android.app.Activity, android.os.Bundle)"
    at android.app.Application.dispatchActivityCreated(Application.java:190)
    at android.app.Activity.onCreate(Activity.java:954)
    at com.stackkedteam.feedshare.DispatchActivity.onCreate(Unknown Source)
    at android.app.Activity.performCreate(Activity.java:6097)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2440)
    at android.app.ActivityThread.access$800(ActivityThread.java:162)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5430)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:913)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)

I have posted the problem and all the code from Dispatch Activity, Gradle, Proguard on StackOverflow here: http://stackoverflow.com/questions/34003991/apk-error-android-app-runs-perfectly-fine-on-emulator-device-but-when-i-downloa

And here is the mapping.txt file (it was too long to be put into stackoverflow): http://pastebin.com/mvS2HGdL

jenyufu
jenyufu
3,311 Points

Harry James, you still there?

Harry James
Harry James
14,780 Points

Hey jenyufu!

Can you please try running your app after deleting the proguard file to see if this fixes the issue.

If not, please rebuild your project as a New Application - copy all of the code from your current app as a New Project.


Let me know how it goes :)

jenyufu
jenyufu
3,311 Points

Harry James, I actually just uploaded the debug apk file to my email and downloaded it to my phone and it worked. So then I did the same with the release apk file but when I download it to my phone, it crashed on start up just like when I download it from the PlayStore. So I'm pretty sure its the proguard file that is the problem. Any suggestion on how to fix the proguard file?

jenyufu
jenyufu
3,311 Points

okay, i think I fixed it.