App crashes using proguard
Asked Answered
J

3

2

My app crashes because of my Proguard error. I have posted this question somewhere too. How can I format the proguard error? Kindly help me out to solve this:

My build.gradle:

apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
    applicationId 'com.quorate.android'
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 3
    versionName "1.2"
    testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.debug
        debuggable true
    }
}
productFlavors {
}
}

configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:24.0.0'
}

dependencies {
testCompile 'junit:junit:4.12'
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.firebaseui:firebase-ui-database:0.4.3'
compile 'com.google.firebase:firebase-auth:9.2.1'
compile 'com.google.firebase:firebase-database:9.2.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.google.firebase:firebase-core:9.2.1'
}

apply plugin: '

My proguard rules pro files:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Vyshnav\AppData\Local\Android\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 *;
#}

-keepattributes Signature
-keepattributes *Annotation*

-keep class com.quorate.android.PostViewHolder.** {
*;
 }

-keepclassmembers class com.quorate.android.User.** {
*;
 }

-keepclassmembers class com.quorate.android.Post.** {
*;
}

 -keepclassmembers class com.quorate.android.Comment.** {
*;
 }

logcat error:

java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class  android.view.View]
at com.a.a.a.d.b(Unknown Source)
 at android.support.v7.widget.ek.c(Unknown Source)
at android.support.v7.widget.fb.a(Unknown Source)
at android.support.v7.widget.fb.c(Unknown Source)
at android.support.v7.widget.dj.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.a(Unknown Source)
at android.support.v7.widget.LinearLayoutManager.c(Unknown Source)
at android.support.v7.widget.RecyclerView.J(Unknown Source)
at android.support.v7.widget.RecyclerView.k(Unknown Source)
at android.support.v7.widget.RecyclerView.t(Unknown Source)
at android.support.v7.widget.RecyclerView.c(Unknown Source)
at android.support.v7.widget.ee.run(Unknown Source)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5930)
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:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by: java.lang.NoSuchMethodException: <init> [class android.view.View]
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getConstructor(Class.java:495)
... 25 more
Jurgen answered 1/8, 2016 at 13:15 Comment(9)
Are we just supposed to guess the reason why your app crashes? Please include your logcatRue
sorry I have edited and added the logcatnowJurgen
this question is actualy my continuation of the following question: #38696508Jurgen
Looks like something got obfuscated and can't find some methodRue
Yes, I can't find that. That's the problemJurgen
This is essentially a duplicate question. You may edit the old one, and delete this, instead of repostingRue
I edited the old one, but no one is answeringJurgen
Patience... You only added the error message 30 mins ago and the question was already downvoted for not including it initially. Now that someone answered here, you can remove the old postRue
What's the need for waiting till death when you need it now?Jurgen
J
2

Ok I solved it myself. Thanks for your help guyz. I appreciate that. I solved it by changing "minify enabled true" to "minify enabled false", since the problem was Proguard. The reason it wasn't shown while debugging through Studio was that Proguard is disabled automatically when "Instant Run" is used. It took 24 hours and a severe eye pain to solve this out. Hope this answer helps someone someday. And StackOverflow Developers...you really need to come up with new features so noobs like me can get answers more fastly.. maybe I should develop that myself!

Jurgen answered 1/8, 2016 at 15:13 Comment(4)
setting minifyEnabled false is a workaround. Often, obfuscation is needed on app that have security assessments/requirements. (Sensitive content or security)Trachyte
Greg, relying on obfuscation for security is a mistake.Indrawn
@Vyshnav Ramesh this is not the correct way to handle this error.Glazed
setting minifyEnabled = false is not recommended as it helps to reduce app size and help in optmization. Issue is obvious, NoSuchMethodException means that your app called a method that not exist and minifyEnabled sometimes removes unused classes, functions and proguard renames those functions with others for security. so, you have to trace that method and keep it in proguard-rules.pro fileNeolith
A
0

Try adding below lines in our proguard.

-keep public class android.support.v7.widget.** { *; } -keep public class android.support.v7.internal.widget.** { *; } -keep public class android.support.v7.internal.view.menu.** { *; }

Else you can try to decode some of logs using -printmapping myapplication.map in proguard file. After decode we can some of actual logs

Autonomous answered 1/8, 2016 at 13:31 Comment(11)
Ok let me see. But the problem is I have to publish it in play store and then check since the app crashes only after publishing. Is there any alternate method to check before publishin? I tried release variant.Jurgen
No need of released version I guess but I am not sure , just sign the apk with your release keys and try.Autonomous
you mean "generate signed apk"?Jurgen
Yes. Generate signed apk and try , if you are facing problem only with Play store apkAutonomous
I have generated signed apk. Now how can I run that? Kindly have patience with me since I'm new to thisJurgen
@VyshnavRamesh Copy the APK to your phone, Use file browser app on phone and click on APK. it will ask to install. Make sure you have untrusted sources ticked in settings. (uninstall debug version first)Scoter
Vyshnav Ramesh Please follow @Doomsknight , you need to enable Unknown sources under Device Adminstration in Security in Settings applicationAutonomous
it asked "Quorate 1.2 replace as 1.4". I pressed install. But it shows "Not installed". I tried multiple timesJurgen
uninstall you application first , reboot once so that no traces are left (actually not required) . Then install Play store version apk.Autonomous
Rahul and Dhoom, i installed finally. Previously "signingConfig signingConfigs.debug" in buildtype release had signed with a default key which I didn't know. And when you told I signed myself which was different than the previous one. Now when I ran I could run the app without any crash. I added the code you answered. But I also added minifyenabled falseJurgen
Now I am waiting to bcheck through play store. I will update after doing so. Thanks guyz. Hope we will meet somewhere some day.Jurgen
N
0

I know that you solved the problem but I hope it help other developers. NoSuchMethodException is your exception as it means that your app call a method that is not exist. it happens as proguard and minifyEnabled=true renames all your classes and functions as well. so, you have to trace your method and keep it.

Neolith answered 13/1 at 3:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.