0

I have a problem with the signed apk --> the following problem does not appear when I install the apk direct from Android Studio by the "play"-Button.

The start of the app is going on without any problems but when I try to click on a view the following exception appears:

java.lang.IllegalStateException: Could not find method openCurrentFeedback(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.Toolbar with id 'toolbar_top'
at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4784)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4748)
at android.view.View.performClick(View.java:5714)
at android.view.View$PerformClick.run(View.java:22589)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

I heard something about the build.gradle and especially the propguard file. This are my current settings of gradle.build:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '24.0.0'
useLibrary 'org.apache.http.legacy'


defaultConfig {
    applicationId "com.app.app"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 7
    versionName "1.06"
    //multiDexEnabled true

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        debuggable true
    }
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
}
testOptions {
    unitTests.returnDefaultValues = true
}
}



dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/PPJASCommon.jar')
compile files('libs/easywsdl/ksoap2-android-assembly-3.6.0-jar-with-dependencies.jar')
compile files('libs/gson/gson-2.2.4.jar')
//for autoresize of text
//dependencies for testing
//junit 4
testCompile 'junit:junit:4.12'
//roboeletric for unittests in the jvm without any (emulated) android device
testCompile 'org.robolectric:robolectric:3.0'
//mockito
testCompile 'org.mockito:mockito-core:1.+'
//power mock, for mock ups
testCompile 'org.powermock:powermock-module-junit4:1.6.2'
testCompile 'org.powermock:powermock-api-mockito:1.6.2'
//robotium for ui tests
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.4'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'com.android.support:support-v4:23.3.0'
compile 'me.grantland:autofittextview:0.2.1'

}

And my propgurard-rule.pro entry:

-keep public class com.app.*

Again: If I installed the app directly from the android studio (no signed apk) the on click function works without any problems.

I'm testing with a samsung galaxy a5 device which runs android 6.0.1.

Does anyone have any ideas?

Edit: openCurrentFeedback-Method

    protected void openCurrentFeedback(View v) {
    if (globals.isFeedbackRunning()) {
        Intent intent = new Intent();
        intent.setClass(v.getContext(), FeedbackManuallyActivity.class);
        startActivity(intent);
    }
}
user99316
  • 111
  • 1
  • 1
  • 5
  • Check your method `openCurrentFeedback(View)` and check the layout who has implemented it. Check if it's spelled okay. – sharp Feb 24 '17 at 13:28
  • it is ok because it worked when i install the app directly from android studio to the same device. i changed nothing in the code doing this. I suspect the propguard, maybe it is removing something .... – user99316 Feb 24 '17 at 13:34
  • Could you post the method `openCurrentFeedback(View)` – sharp Feb 24 '17 at 13:39
  • 1
    Make your method `public` and try. – sharp Feb 24 '17 at 13:42
  • The method is an base class with extends AppCompatActivity. This Base class a superclass for every activity class because every activity is implenting the view. So i dont have to implement the onClick method in every activity class, that why it is in the superclass. – user99316 Feb 24 '17 at 13:49
  • I changed it to public, now it is working - dont understand why ... – user99316 Feb 24 '17 at 13:49
  • @user99316 the method referred from `onClick` in XML should be `public` in Java. I don't know why. – Sufian Feb 24 '17 at 15:25

1 Answers1

0

sorry for not enough reputation for comment. The reason crash to me seems like the button in the xml layout directly use

onclick="openCurrentFeedback"

Thus, proguard encrypted and renamed the code ,and the method is changed and different to the name you declared in xml.

Just some infomation, if you want keep the protected instead of public, you may add in proguad to keep that method:

-keep class package.TheClass {
  protected void openCurrentFeedback(android.view.View);
}

Anyway, this answser credit should be FiN's :)

CbL
  • 734
  • 5
  • 22