Run Android app in debugging mode
Asked Answered
U

1

8

My Android Studio version is 2.3.3

In my Android app gradle build, I have explictly defined different server_url string values for debug type and release type:

buildTypes {
        debug {
            resValue "string", "server_url", "https://myserver.debug.com/"
        }
        release {
            resValue "string", "server_url", "https://myserver.com/"
            ...
        }
    }

In my code, I get the string value by:

String url = context.getString(R.string.server_url);

I connected my Android phone to my laptop. The Android studio toolbar looks like this: enter image description here

I also selected build variants to be "debug":

enter image description here

I click the enter image description here, the app is running on my phone, however, it uses server_url value defined in release type. Why?

(Under build/generated/res/resValues/debug/generated.xml & build/generated/res/resValues/release/generated.xml I see those values, no problem there eihter.)

==== Update ===

Adding defaultPublishConfig 'debug' fixed the issue (Thanks @Ulug Toprak), but I am still wondering why Android Studio doesn't work without it though I have set Build Variant to "Debug". Maybe a bug in Android Studio?

Unbend answered 21/7, 2017 at 13:50 Comment(6)
Do you try to clean the project before run?Irony
Yes, I tried cleaning the project before running. It doesn't help.Unbend
you can try adding defaultPublishConfig "debug" to your build.gradlePit
have you added jnidebug ?Stonedeaf
Why don't you use productFlavors?Trochelminth
glad the work around worked, can you investigate if the publishNonDefault in the library build.gradle set the false by any chance?Pit
P
1

Just to answer your updated question,

Multi module setup (application + android library) will not log annotated methods/classes from Android Library Module but will do it on Android Application Module. The reason behind this, is that the Android Gradle Plugin will build all Android Libraries as release versions.

as suggested in the comments adding defaultPublishConfig "debug" to the build.gradle file will force the debug version

Pit answered 21/7, 2017 at 14:28 Comment(1)
Yes, after set publishNonDefault 'debug' in the library build.gradle, it works.Unbend

© 2022 - 2024 — McMap. All rights reserved.