Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install debug and release version on same device

I have configured build variants in my project with applicationIdSuffix so that I can install both debug and release versions on my device. here is my build.gradle (relevant parts):

 buildTypes {
        debug {
            buildConfigField "String", "BASE_URL", '"http://dev.xyz.com"'

            applicationIdSuffix ".debug"
        }
        release {
            buildConfigField "String", "BASE_URL", '"http://api.xyz.com"'
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

But when I try to install both, it fails. I tried different ways:

1. Generated both debug and release apks and transferred them to my phone storage. The first one installs, and the second one gives an error "App not installed" - no further info. This is the same no matter which version I install first.

2. Installed debug version from storage, then tried to install release version from play store, but play store gives error :

cant install app error code:-505.

3. Installed release version from store, and then tried running the project from android studio, and this is my 'run' log :

    Launching app
    $ adb push D:\myPROJECTS\MyApp\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.myapp.debug
    $ adb shell pm install -r "/data/local/tmp/com.example.myapp.debug"
    java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String android.os.SystemProperties.native_get(java.lang.String) (tried Java_android_os_SystemProperties_native_1get and Java_android_os_SystemProperties_native_1get__Ljava_lang_String_2)
      at android.os.SystemProperties.native_get(Native Method)
      at android.os.SystemProperties.get(SystemProperties.java:52)
      at android.os.Environment$UserEnvironment.<init>(Environment.java:123)
      at android.os.Environment.initForCurrentUser(Environment.java:98)
      at android.os.Environment.<clinit>(Environment.java:92)
      at android.os.Environment.getLegacyExternalStorageDirectory(Environment.java:597)
      at android.os.Debug.<clinit>(Debug.java:103)
      at android.ddm.DdmHandleHello.handleHELO(DdmHandleHello.java:164)
      at android.ddm.DdmHandleHello.handleChunk(DdmHandleHello.java:91)
      at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
    java.lang.UnsatisfiedLinkError: android.os.Debug
      at android.ddm.DdmHandleHello.handleFEAT(DdmHandleHello.java:176)
      at android.ddm.DdmHandleHello.handleChunk(DdmHandleHello.java:93)
      at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
    java.lang.UnsatisfiedLinkError: android.os.Debug
      at android.ddm.DdmHandleProfiling.handleMPRQ(DdmHandleProfiling.java:187)
      at android.ddm.DdmHandleProfiling.handleChunk(DdmHandleProfiling.java:88)
      at org.apache.harmony.dalvik.ddmc.DdmServer.dispatch(DdmServer.java:171)
    Aborted 

    $ adb shell am start -n "com.example.myapp.debug/com.example.myapp.LoginActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Error while executing: am start -n "com.example.myapp.debug/com.example.myapp.LoginActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.myapp.debug/com.example.myapp.LoginActivity }
    Error type 3
    Error: Activity class {com.example.myapp.debug/com.example.myapp.LoginActivity} does not exist.

    Error while Launching activity

any idea what is going on?

Update : don't know if it helps, but here is how I declared my launcher activity in androidmanifest.xml :

<activity
    android:name=".LoginActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.Launcher">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
like image 310
ShahiM Avatar asked Aug 26 '16 14:08

ShahiM


People also ask

Can I run debug APK on device?

STEPS TO CREATE 'DEBUG APK' IN ANDROID STUDIO Open android studio, in menu-> Build -> Build Bundle(s) / APK(s) -> Build APK (s). Step 2: Click on 'locate' in bottom right pop up when APK is built, it will show where the APK file has been generated, and now you can run this APK in Android device.

How do I enable debug on APK?

To start debugging an APK, click Profile or debug APK from the Android Studio Welcome screen. Or, if you already have a project open, click File > Profile or Debug APK from the menu bar. In the next dialog window, select the APK you want to import into Android Studio and click OK.

How can you debug your app when it's already released?

Set some breakpoints in the app code. In the toolbar, select a device to debug your app on from the target device drop-down menu. If you don't have any devices configured, then you need to either connect a device via USB or create an AVD to use the Android Emulator.

What is the difference between debug APK and release APK?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.


1 Answers

Okay, I figured out what was going on.

I was actually creating an unsigned apk for the debug variant (Build > Build APK). But I had to use (Build > Generate Signed APK) and then select the debug variant from the options.

enter image description here

Also, when running the project on my device, gradle would be generating an unsigned apk. So that too wouldn't work. That is - unless I configure SigningConfigs as explained in this answer.

like image 138
ShahiM Avatar answered Oct 23 '22 13:10

ShahiM