-3

This is my first application to deploy on PlayStore, and I'm facing some issues regarding the generated signed APK.

When I run the app using android studio 2.3.3 (using ADB) on my phone (API 21 Android 5.0.1), the app works fine without any problem. When I generate the apk (with V1 and V2 checked) and Install it on the same phone, it shows the splash screen and then when I press the button (Login) the app shuts down.

I tried to use Android monitor to see the cause of it, and the monitor says that (Method login (onClick method for login button)) is not implemented, but it is implemented.

 java.lang.IllegalStateException: Could not find method login(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'login_button'

The header of the method is

protected void login(View v) throws IOException, InterruptedException {}

login method

// Login button onClick method
protected void login(View v) throws IOException, InterruptedException {
    if (checkBox.isChecked()){
        // save password
        SharedPreferences sharedPreferences = 
        Login.this.getSharedPreferences(
                "LOGIN_INFO",MODE_PRIVATE
        );
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("PASSWORD",event_key_edittext.getText().toString());
        editor.putBoolean("CHECKBOX_VALUE",checkBox.isChecked());
        editor.commit();
    }
    else{
        // clear sharedprefrences
        SharedPreferences sharedPreferences = 
        Login.this.getSharedPreferences(
                "LOGIN_INFO",MODE_PRIVATE
        );
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    // get the key
    event_key = event_key_edittext.getText().toString();
    // check internet before checking with the api
    if (internetConnectionAvailable(2000)) new VerifyLoginTask().execute();
    // if no internet, show msg
    else internet_msg.setVisibility(View.VISIBLE);
}

XML for Login Activity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context="agha.ticket_app.Login">

<ImageView
    android:id="@+id/login_circles"
    android:layout_width="match_parent"
    android:layout_height="105dp"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:src="@drawable/dectop" />

<ImageView
    android:id="@+id/login_icon"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_below="@id/login_circles"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="40dp"
    android:src="@drawable/app_icon" />

<TextView
    android:id="@+id/login_txt_login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/login_icon"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:text="@string/login_main_txt"
    android:textColor="@color/colorGreen"
    android:textSize="20dp" />

<TextView
    android:id="@+id/login_txt_password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/login_txt_login"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:text="@string/login_sub_txt"
    android:textColor="@color/colorPink"
    android:textSize="10dp" />

<EditText
    android:id="@+id/login_edit_password"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/login_txt_password"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:hint="@string/login_edittext_hint"
    android:inputType="text"
    android:maxLines="1"
    android:singleLine="true"
    android:textColor="@color/colorPink"
    android:textColorHint="@color/colorPink"
    android:textColorLink="@color/colorGreen"
    android:textSize="15dp"
    android:theme="@style/MyEditTextTheme" />

<TextView
    android:id="@+id/login_error_txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_edit_password"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:text="@string/login_incorrect_pass"
    android:textColor="#011627"
    android:textStyle="bold"
    android:visibility="invisible" />

<TextView
    android:id="@+id/login_internet_txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_edit_password"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:text="@string/connection_error"
    android:textColor="#011627"
    android:textStyle="bold"
    android:visibility="invisible" />

<CheckBox
    android:id="@+id/login_checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/login_error_txt"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="15dp"
    android:buttonTint="@color/colorPink"
    android:text="@string/login_check_box"
    android:textColor="@color/colorGreen"
    android:textSize="10dp" />

<Button
    android:id="@+id/login_button"
    android:layout_width="200dp"
    android:layout_height="40dp"
    android:layout_below="@id/login_checkbox"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dp"
    android:background="@drawable/login_button_bg"
    android:elevation="15dp"
    android:onClick="login"
    android:text="@string/login_button"
    android:textColor="#FFFFFF" />

    </RelativeLayout>

How can I solve this problem?

2 Answers2

1

The problem is not with apk its login button.

Follow these step :

  1. implement OnClickListener in your class
  2. initialize the button in onCreate() Button button = (Button) findViewById(R.id.login_button);
  3. set the setOnClickListener() method for button button.setOnClickListener()
  4. then call the method outside of oncreate() public void accountButton (View v){ //do some thing which you want }

Hope this might work.

Sahdeep Singh
  • 1,342
  • 1
  • 13
  • 34
0

If it runs fine in Android Studio don't test it only this way. Android Studio does not always perform a complete re-install of the app if you execute "Run" or "Debug". Instead it patches the App at run-time, the app may be even running while patching (aka "Instant Run").

Therefore you should uninstall the app from the device and then install it again to test it. This should be a similar environment as the users loading to from Google Play.

Furthermore you could create the signed APK and install it onto a device manually via adb. Again don't forget to uninstall other versions of the app so that you start fresh. Otherwise existing files i the private app directory may change the behavior of your app.

Robert
  • 39,162
  • 17
  • 99
  • 152