connectedAndroidTest and release build type - android

I'm using gradle:1.2.3
I would like to run my androidConntectTests (instrumentation tests) on release (signed, minified) configuration, but I cannot.
My build types:
buildTypes {
debug {
minifyEnabled false
debuggable true
}
robotium {
debuggable true
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
debuggable false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I have read, that those tests can only be run on debbugable configurations, so I made "robotium" build type (see above), but it still does not work.
When I try calling "gradle tasks" it shows only connectedAndroidTest-Flavour-Debug, and calling "connectedAndroidTest-Flavour-Release/Robobium" simply fails with "task XXX not found in root project".
Is there any way to make instrumentation tests run on diffrent build type?

The android gradle plugin will create test variants for all your flavors. To switch the build type used you can do this, as stated in the documentation
Currently only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with:
android {
...
testBuildType "staging"
}

Related

React native android build gradle debuggable false does not turn off __DEV__

Hi I cannot found any answer solution for this
I have follwoing custom variant in \android\app\build.gradle
I have tried put debuggable false
But this does not changed __DEV__ to false.
Everyone is telling debug variant and release variant but nobody is telling how exactly a specific toggle to change __DEV__ to false.
Please help thanks.
buildTypes {
alpha {
signingConfig signingConfigs.dev
debuggable false
...
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
matchingFallbacks = ['release', 'debug']
}
}
also I have tried removed 'debug' from matchingFallbacks not working as well.
matchingFallbacks = ['release']
If im not mistaking you are looking at it wrong. As the link below mentions.
You can use the DEV global variable in JavaScript to determine if you're using React Native packager or not. If you are running your app in the iOS Simulator or Android emulator DEV will be set to true.
React Native DEV and PROD variables
As long as your running the app on emulators the __DEV__ variable will be true.
You can try to run in a simulator with --configuration Release
I'm experiencing this problem too, in my case the buildType name should contain "release" keyword. (don't ask me why)
Change alpha to alphaRelease and everything should works fine.
Example:
(I'm using RN 0.68.2)
buildTypes {
debug {
signingConfig signingConfigs.debug
debuggable true
applicationIdSuffix ".dev"
}
alphaRelease {
initWith release
matchingFallbacks = ['release']
signingConfig signingConfigs.hmg
debuggable false
applicationIdSuffix ".hmg"
}
release {
/* Add the firebaseCrashlytics extension (by default, it's disabled to improve build speeds) and set
* nativeSymbolUploadEnabled to true along with a pointer to native libs. */
firebaseCrashlytics {
nativeSymbolUploadEnabled true
unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
}
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
debuggable false
applicationIdSuffix ""
}
}

Generating signed apk stucks when minifyEnabled true is used

While generating releases apk with minify enabled true ,gradle build doesn't finish and stucks at app:crashlyticsUploadDeobsRelease.
gradle build log
Replace your build Types code with this code in app level gradle file. when you are debugging or running code on your device before final release then select built variant debug and when you are going to built signed apk for release then select built variant release
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Custom build Type not working on androidTest building

Hi i am trying to build a androidTest APK based on a flavour and a custom build type i have defined below:
productFlavors {
FlavourOne {
applicationIdSuffix ".live"
buildConfigField 'String', 'SERVER_BASE_URL', '"http://live.com"'
}
FlavourTwo {
applicationIdSuffix ".demo"
buildConfigField 'String', 'SERVER_BASE_URL', '"http://demo.com"'
}
}
buildTypes {
debug {
minifyEnabled false
// shrink code (remove unused classes and methods) - note that it falls back to experimental shrinker for Instant Run
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-debug.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-test.pro'
}
release {
minifyEnabled true // shrink code (remove unused classes and methods)
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debugDemo {
applicationIdSuffix '.demo'
versionNameSuffix '-DEMO'
minifyEnabled false
// shrink code (remove unused classes and methods) - note that it falls back to experimental shrinker for Instant Run
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-debug.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-test.pro'
}
demo {
applicationIdSuffix '.demo'
versionNameSuffix '-DEMO'
minifyEnabled true // shrink code (remove unused classes and methods)
shrinkResources false // don't strip unused res files
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
When i run gradlew assembleFlavourOneDebugDemoAndroidTest i get an error straight away saying
Task 'assembleFlavourOneDebugDemoAndroidTest' not found in root project 'MyProject'.
It works fine if i omit my custom buildType and just do assembleFlavourOneAndroidTest and it works. It also works if do assembleFlavourOneDebugANdroidTest only...
According to the documentation only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with:
android {
testBuildType "demo"
}
and your gradle task after sync should look like this:
./gradlew assembleFlavourOneDemoAndroidTest
and be careful there will be NO debug as you pointed out in your description at the end.
assembleFlavourOneDebugDemoAndroidTest
I faced the similar problem,
I need debug build type when develop,
debugMinify build type when run androidTest on pipeline or assembleAPK
so follow bellow code ,
You can run androidTest on debug type when develop
and when you run assemble APK command , testBuildType will be changed
android{
buildTypes{
release{}
debug{}
debugMinify{}
}
testBuildType getCurrentVariant()
}
def getCurrentVariant() {
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
println(tskReqStr)
if (tskReqStr.contains("assemble") && tskReqStr.contains("DebugMinify")) {
print("buidType: debugMinify")
return "debugMinify"
} else {
print("buidType: debug")
return "debug"
}
}
and
gradlew assembleDevelopDebugMinify
gradlew assembleDevelopDebugMinifyAndroidTest
[DefaultTaskExecutionRequest{args=[assembleDevelopDebugMinify],projectPath='null'}]
buidType: debugMinify
I'd assume some declarations lack the initWith instruction -
because any test build rigidly depends on initWith debug.
When using initWith release, no test tasks are generated.
debugDemo {
initWith debug
...
}
The initWith property allows you to copy configurations from other build types, then configure only the settings you want to change.

Release apk won't run

I'm building release APK with flutter run --release but I'm getting this exception
Failed to register native method io.flutter.view.FlutterNativeView.nativeRunBundleAndSource(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V in /data/app/com.example.myapp-1/base.apk
However, debug variant runs normally so if I run the app just with flutter run everything is fine.
By the way, I'm executing flutter clean before avery build.
What is the cause of this?
Found the solution on my own, but I'm posting this answer for people who are having the same problem.
Turns out that build.gradle was causing exception
shrinkResources true // for this to work minifyEnabled must be set to true
minifyEnabled true // if set to true apk will not build
Solved it by using only proGuard so snippet below is working buildTypes section of app-level build.gradle
buildTypes {
release {
debuggable false
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

ProGuard doesn't obfuscate when building alternative buildType from Android Studio

So in a few words ProGuard doesn't obfuscate sources when I build alternative buildType from Android Studio but works when I use "Generate Signed APK..." option to create apk file.
And some more details here: Android Studio 2.1.1, Gradle version: 2.10, plugin version .2.1.0
I've 3 build types with the following configuration:
buildTypes {
release {
minifyEnabled true
...
proguardFile 'proguard-rules.pro'
proguardFile getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
releaseDebug {
debuggable true
minifyEnabled true
...
proguardFile 'proguard-rules.pro'
proguardFile getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
debug {
debuggable true
minifyEnabled false
...
proguardFile getDefaultProguardFile('proguard-android.txt')
testProguardFile 'proguard-rules-test.pro'
signingConfig signingConfigs.release
}
}
I run application directly from Android Studio and have such results:
release - obfuscated
releaseDebug - NOT obfuscated
debug - not obfuscated
When I use "Generate Signed APK..." option:
release - obfuscated
releaseDebug - obfuscated
debug - not obfuscated
Is it a build system issue or I missed something?
P.S. Just for clarification, minifyEnabled is already enabled for releaseDebug build type and ProGuard is working but not in this particular case. This is not related to debug mode.
Finally, after some tests, I recognized that this issue is caused by debuggable true statement in releaseDebug configuration.
So Android Studio (or Gradle) will not use ProGuard obfuscation if you use debuggable true and minifyEnabled true statements in your alternative build type.

Categories

Resources