I have an Android Studio project that contains several sub-projects (aka: modules).
I would like to build some of these sub-projects from the command line.
I read on the Android dev guide that you can build your project by simply running
gradlew.bat assembleDebug
from the command line, however this always builds the entire project (all the modules)
I just want to assemble a single module, how do I do that?
Another way to do this is:
gradlew.bat :myModule:assembleDebug
https://stackoverflow.com/a/16987319/1807627
gradlew.bat assembleDebug -a -b path/to/module/build.gradle
-a only builds the component and does not rebuild its dependencies
Use -b to specify another Gradle build file. In this case, the module's instead of the top-level build.gradle.
If you weren't using the Gradle wrapper, you could alternatively just cd to the module directory and run gradle assembleDebug -a there.
Related
I am writing a Gradle task around Robolectric in Android Studio. How can I delete the jars that it downloads at runtime? I need a clean slate to test my task.
I tried running clean but that didn't cause the jar to be redownloaded on next run.
Is there a command I can run? Or where can I find the directory for downloaded jars?
I could not find a designated clean command, but I found a workaround:
Run test with debug flag -d; can be set either in Preferences>Compiler>Command-line Options, or run from terminal with ./gradlew :app:testDebugUnitTest -d --tests com.package.YourTestClass.testMethod > gradle_log.txt 2>&1
In the logs, search for this: Dependency cache location:
The destination directory be specified on that line. Then you can just remove it rm -r /var/folders/directoryname
I am trying to use gitlab/fastlane to build my project.
When i execute the scripts in the default project they work correctly, but when the runner checks out the project the build fails with the message "Task 'assembleRelease' not found in root project 'projectname'".
When i open the CI project location in Android Studio I have to execute "sync project with gradle files" before build is available.
After I have done this i can execute ./gradlew assembleRelease (and the fastlane script also works correctly)
The console output shows that several files/directories are removed when the repository is checked out:
Removing .gradle/
Removing .idea/
Removing app/app.iml
Removing app/build/
Removing build/
Removing local.properties
Removing project.iml
I can't seem to find what exactly Android Studio does when I select "Sync Project with Gradle Files" and how i reproduce that with my build script.
I had the same problem. The reason was that the ANDROID_HOME environment variable was not set and the local.properties file did not have an sdk.path set.
You could set it via Jenkinsfile into the local.properties file:
sh 'echo "sdk.dir=/<your_path_to_Android_SDK>" > ./local.properties'
in my case:
sh 'echo "sdk.dir=/home/jenkins/Android/Sdk" > ./local.properties'
Instead of writing it into the Jenkinsfile you could also create a custom fastlane lane which calls the the above mentioned shell command before you execute ./gradlew assembleRelease
I'm trying to build Android projects on the OSX (Mavericks 10.9.5) command line using this how-to: http://developer.android.com/tools/building/building-cmdline.html.
This How-To explains the use of assembleDebug/assembleRelease to build an Android project.
Unfortunately gradle doesn't create the assembleDebug or assembleRelease targets.
Executing ./gradlew assembleDebug returns this:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'assembleDebug' not found in root project 'test'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.826 secs
Steps:
android create project
The test project has been created with android create project --path . --name "DummyAPK" --target android-21 --package com.dummyapk.dummyapk --activity DummyActivity
which returned
Created directory /Users/user/Documents/test/src/com/dummyapk/dummyapk
Added file ./src/com/dummyapk/dummyapk/DummyActivity.java
Created directory /Users/user/Documents/test/res
Created directory /Users/user/Documents/test/bin
Created directory /Users/user/Documents/test/libs
Created directory /Users/user/Documents/test/res/values
Added file ./res/values/strings.xml
Created directory /Users/user/Documents/test/res/layout
Added file ./res/layout/main.xml
Created directory /Users/user/Documents/test/res/drawable-xhdpi
Created directory /Users/user/Documents/test/res/drawable-hdpi
Created directory /Users/user/Documents/test/res/drawable-mdpi
Created directory /Users/user/Documents/test/res/drawable-ldpi
Added file ./AndroidManifest.xml
Added file ./build.xml
Added file ./proguard-project.txt
gradle init
After that I executed gradle init, which returned
:wrapper
:init
BUILD SUCCESSFUL
gradlew tasks
Querying the available tasks with gradlew tasks returns (isn't there missing something?)
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project 'test'. [incubating]
dependencies - Displays all dependencies declared in root project 'test'.
dependencyInsight - Displays the insight into a specific dependency in root project 'test'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'test'.
properties - Displays the properties of root project 'test'.
tasks - Displays the tasks runnable from root project 'test'.
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 3.474 secs
My Java version is
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
..and Gradle version (installed via brew) is
------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_60 (Oracle Corporation 24.60-b09)
OS: Mac OS X 10.9.5 x86_64
What am I missing to be able to build an Android project on the command line?
android create project does not create a gradle friendly structure. It creates an ant friendly structure. You have two options depending on your intentions.
use ant to build your project ( not currently supported by Android team )
use Android Studio to generate a gradle friendly project structure.
num 2 is the recommended approach by the Android team. It's as simple as dl'ing Android Studio and creating a new project. From there you should be able to create a new project that can be built with ./gradlew build
try This:
./android create project -p AppPAKTGV -a Main -k com.example.apppaktgv -t android-23 -g -v 0.11.+
it's works but when i try target 24 or 25 not work i don't now
Try to do this and note
a) you need to type tools/android under Step 3 (like step 2: Execute)
-- but as said the ant structure is not helpful
-- not sure I can go from there
b) I follow the advice and also ensure get the platform-tools
-- I can build
-- I can get that .apk
-- I can adb install (I rename any existing .apk)
Seems working!
Now I'm configuring Travis CI for my Gradle-based Android project. Is it possible to temporary disable tests launch from Travis to just know - if project could be built or not?
By default, Travis-ci executes ./gradlew build connectedCheck if no script: section is found.
Failed tests are ignored if you add the next code to all your tested modules (build.gradle files).
project.gradle.taskGraph.whenReady {
connectedAndroidTest {
ignoreFailures = true
}
}
Another option is to skip the install stage and only to use ./gradlew build (or ./gradle build without gradle wrapper) so tests are not performed.
install:
# Check install section: http://docs.travis-ci.com/user/build-configuration/#install
# If you'd like to skip the install stage entirely, set it to true and nothing will be run.
- true
script:
# By default Travis-ci executes './gradlew build connectedCheck' if no 'script:' section found.
- ./gradlew build
You can use the -x command line argument which excludes any task (see this answer).
gradle build -x test
Check output of
./gradlew tasks
and then use:
./gradlew assemble
Like in this thread:
Gradle build without tests
In an attempt to compile external jars, I have to use the terminal and do a clean. However, when I go into the root directory of my project and execute
gradlew clean
I get the following message:
-bash: gradlew: command not found
Here's a screenshot of my application folder's home directory.
Let me know if you need anything else, I'm not sure why this is happening.
gradlew is not in your global path. To execute the 'clean' task (or any task for that matter) using the gradle wrapper (gradlew) in your project directory in your terminal, specify the current directory with the './':
./gradlew clean
You need to give it the permission by running this one first:
chmod 777 gradlew
gradlew is not in your global path. To execute the 'rebuild' task (or any task for that matter) using the gradle wrapper (gradlew) in your project directory in your terminal, specify the current directory with the './':
./gradlew rebuild