Let's say I have a build variant named debugAutomation.
I wan't to build this variant into .*apk file using gradle command. I do:
./gradlew assembleDebugAutomation
This provides me with application .*apk. But to perform automation tests in espresso I also need test .*apk. So I do again:
./gradlew assembleDebugAutomationAndroidTest
And .*apk with -androidTest is in my outputs/apk/ folder of my project.
Where is the trick and problem?
a) while performing assembleDebugAutomation I have only application .*apk built.
b) while performing assembleDebugAutomationAndroidTest then during build process THIS APK BEING INSTALLED ON ALL CURRENTLY VISIBLE DEVICES IN ADB.
My question is: How can I build androidTest .*apk with gradle command so it ONLY BUILDS APK and DOESN'T INSTALL IT on currently visible devices in ADB during build process?
To just assemble into an APK:
./gradlew assembleDebug
That will build however, but won't do any automation tests, nor would it install to devices.
./gradlew assembleDebug
Builds the debug APK.
./gradlew assembleDebugAndroidTest
Builds the test APK
Or if you have a flavour in your gradle file it would be:
./gradlew assemble<FlavourName>DebugAndroidTest
Related
Context: I am trying to solve the following error: Task 'assembleRelease' not found in root project 'android'. from CircleCi when it works fine on my local machine.
I noticed if I ran (both locally and on the ci server) ./android/gradlew tasks it doesn't have any "Build tasks".
However if I move into the directory where gradlew lives and try again, I get all the Build Tasks reported.
cd android && ./gradlew tasks
Why is there a difference in what tasks gradlew reports, depending on the directory from which it was called?
I'm using Fastlane to automate my builds with bundle exec fastlane android beta from ./ (rather than ./android)
This morning I generated an apk via this command:
./gradlew bundleRelease
which generated the following:
However, now I need to generate a newer version of the apk as I made some changes to the application.
I tried just running the above command again, but that did not seem to work. The files are all the same ones. How do I regenerate an apk? Do I need to delete the old ones first?
Clean your older build first using
./gradlew clean
Then build your apk using
# for debug
./gradlew assembleDebug
# for release
./gradlew assembleRelease
# if you want all the build variants, just using below command
./gradlew assemble
Your apks can be found inside output/apk directory
bundleRelease generates a bundle - filing in just the bundle directory you see. You should be using assembleRelease if you want to generate an APK and the apk directory:
./gradlew assembleRelease
I'm trying to run automated tests for an Android project via the command line. However, gradlew test doesn't execute any tests unless I use gradlew clean test or gradlew test --rerun-tasks. Running gradlew test -i shows the following message:
Skipping task 'app:test' as it has no actions
I was able to run gradlew test without problems when I worked on another project for a previous job. Am I doing something wrong? Or is this due to differences between Gradle versions?
This isn't a big deal, except gradlew clean test and gradlew test --rerun-tasks take much longer to run.
Every time when I need to build the debug and release ver for the QA what I do:
In BuildVariants change to Debug make a build APK.
Then I change the BuildVariants to Release and build one more APK.
So, question is if it is possible to build two versions at the same time?
If you go to the root folder of the proyect, you can compile the debug version using the command line:
gradlew.bat assembleDebug
Or if you want to compile a release:
gradlew.bat assembleRelease
Takng that into account, you can create a script, named "compile.bat" for example, with this content:
#echo off
title Compiling...
echo Compiling the debug and realease apk's...
gradlew.bat assembleDebug
gradlew.bat assembleRelease
#echo Finished!
pause
You can build an APK through the terminal, then you can launch as many build processes as you like.
$ ./gradlew assembleFlavouraFlavourbRelease & ./gradlew assembleFlavouraFlavourbDebug &
How to create an anpk file using gradle script.I have one android project.I want to create its apk but using gradle script not through android studio.
Is there any such script which will create apk.
You can use gradlew script to build your apk file. Gradlew script is part of the project which is created using Android Studio. You can run gradle script like this
gradlew assembleDebug
or
gradlew assembleRelease
first option will generate apk in debug configuration. Second will generate release APK. There is also several other things that you need to prepare before you run this script. The most important thing is that you need to create keystore and point it in your gradle file.
To create keystore you can use this command:
keytool -genkey -v -keystore keystore.jks -alias your-alias -keyalg RSA -keysize 2048 -validity 10000
keytool should be placed in bin folder in your java root directory.
If you run gradle tasks you will see available task for your project. Here is the Build section
Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleDebugAndroidTest - Assembles the android (on device) tests for the Debug build.
assembleRelease - Assembles all Release builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
clean - Deletes the build directory.
compileDebugAndroidTestSources
compileDebugSources
compileDebugUnitTestSources
compileReleaseSources
compileReleaseUnitTestSources
mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.
So
gradle build
should do the job
You can create your own script using available gradle commands.
Here is a detailed article for build, test and deploy via bash script.
Following is the sample script you can use.
enter code
#Define all paths, constants here
PROJECT_DIR='/Users/mayuri/CODE/AndroidBuildAutomationSample/'
OUTPUT_DIR='/Users/mayuri/CODE/AndroidBuildAutomationSample/OUTPUT_DIR/'
#Enter project dir
cd $PROJECT_DIR
#Start Build Process
echo "\n\n\nCleaning...\n"
./gradlew clean
echo "\n\n\ncleanBuildCache...\n"
./gradlew cleanBuildCache
echo "\n\n\n build...\n"
./gradlew build
echo "\n\n\n assembleDebug...\n"
./gradlew assembleDebug
#Install APK on device / emulator
echo "installDebug...\n"
./gradlew installDebug
Remember to give execute permissions to your script file
chmod +x automate.sh
Execute the following commands from the directory of the associated project.
# build project, runs both the assemble and check task
gradle build
# build project complete from scratch
gradle clean build
# speedup second grandle build by holding it in memory
gradle build --daemon
By default, the Gradle build creates two .apk files in the build/outputs/apk folder. Check this link for further information
.