Set environment in AWS codebuild for Android build - android

I am trying install Android environment in AWS server.
Here it is buildspec.yml file that contain set of command to install
Android SDK, NDK and gradlew for generate android build .
SDK and NDK for Android successfully downloaded and installed at AWS Ubuntu system. Even I can see a log for ./gradlew build that build
successfully.
buildspec.yml
version: 0.1
phases:
install:
commands:
- echo Nothing to do in the install phase...
- sudo apt-get -y install wget
pre_build:
commands:
- echo Nothing to do in the pre_build phase...
- wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
- tar zxvf android-sdk_r24.4.1-linux.tgz
- mkdir -p android-sdk-linux/licenses
- cp android-sdk-license ./android-sdk-linux/licenses/
- echo sdk.dir='pwd'/android-sdk-linux > local.properties
- wget https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip
- unzip android-ndk-r13b-linux-x86_64.zip
- export ANDROID_NDK_HOME=`pwd`/android-ndk-r13b
- export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${ANDROID_NDK_HOME}
- echo "sdk.dir=$ANDROID_HOME" > local.properties
- echo "ndk.dir=$ANDROID_NDK_HOME" >> local.properties
build:
commands:
- root/./gradlew --debug --stacktrace build
- root/./gradlew assemble
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- Monoca/app/**/*
While I try to execute ./gradlew assemble command for Android build it can generate application file (.apk) in Android output directory in Android Studio
but unfortunately it's not working in AWS CodeBuild environment.
Anyone have deep insight regarding this issue ? Please suggest if you find anything wrong in set up part.
I have followed this tutorial for AWS CodeBuild.

I think the problem here is with propagating the environment variable values across commands that CodeBuild does not follow. CodeBuild executes each commands in fresh shell. The last 2 commands would essentially set sdk.dir and ndk.dir variables to be empty (you can validate this by running cat local.properties).
- echo "sdk.dir=$ANDROID_HOME" > local.properties
- echo "ndk.dir=$ANDROID_NDK_HOME" >> local.properties
The right approach here would be to move your build logic to a script that gets executed from the buildspec.yml
- ./my-gradle-build.sh
or
Not use the environment variables to set variables in local.properties, but use paths instead.
- echo sdk.dir='pwd'/android-ndk-r13b > local.properties
- echo ndk.dir='pwd'/android-ndk-r13b >> local.properties
I hope this helps.
Thanks!

Related

How to setup Travis CI for an Android Project which uses both NDK and SDK to build

I've searched in so many places, even in Travis CI documentation page but I couldn't find the solution of my problem. The issue is - I already have an Android Project set up on Travis CI which works fine. Now, I have some requirement where I need to compile some native files for my project. In my local machine, the set up works perfectly as I've SDK and NDK installed. When I push the code the Travis complains about the NDK. So, I looked for how to set up the NDK for Travis. I followed below links ---
https://github.com/googlesamples/android-ndk/blob/master/.travis.yml
Travis: how to know android sdk/ndk path?
https://github.com/travis-ci/travis-ci/issues/5395
But none of the above worked. My travis.yml file is in below --
# which language/platform is used
language: android
# JDK version
jdk:
- oraclejdk8
# root permission required?
sudo: required
dist: precise
# Environment variables
env:
global:
- BRANCH_NAME=$TRAVIS_BRANCH
# android components required to build code
android:
components:
- tools
- platform-tools
- build-tools-25.0.3
- android-24
- extra-android-m2repository
- extra-google-m2repository
- extra-google-google_play_services
# clean up old stuff before we get started
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
# cache directories to use
cache:
directories:
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
# Configurations to set up Android NDK
before_install:
- rm -fr $HOME/android-ndk-r16b
- curl -L http://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O
- unzip -oq android-ndk-r16b-linux-x86_64.zip
- rm android-ndk-r16b-linux-x86_64.zip
- export ANDROID_NDK_HOME=$HOME/android-ndk-r16b
- export PATH=$PATH:${ANDROID_NDK_HOME}
# Build script - which configs and creates the builds
script: "./my_script.sh"
With this setup Travis CI recognizes the NDK but while running my build script it's unable to find it. Below is the log for my Travis build --
android.install
Installing Android dependencies
creating directory /home/travis/.gradle/caches
adding /home/travis/.gradle/wrapper to cache
creating directory /home/travis/.gradle/wrapper
$ java -Xmx32m -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
$ javac -J-Xmx32m -version
javac 1.8.0_111
before_install.1
$ rm -fr $HOME/android-ndk-r16b
before_install.2
$ curl -L http://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O
before_install.3
$ unzip -oq android-ndk-r16b-linux-x86_64.zip
before_install.4
$ rm android-ndk-r16b-linux-x86_64.zip
before_install.5
$ export ANDROID_NDK_HOME=$HOME/android-ndk-r16b
before_install.6
$ export PATH=$PATH:${ANDROID_NDK_HOME}
$ ./build_cc_app.sh
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/3.3/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing
Parallel execution with configuration on demand is an incubating feature.
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /home/travis/android-ndk-r16b.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
NDK is missing a "platforms" directory.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':client'.
> NDK not configured. /home/travis/android-ndk-r16b
Download it with SDK manager.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 29.479 secs
The error message says it is missing the platforms directory. You could probably investigate further by requesting that debug is enabled on your repository:
Running build in debug
This feature is available for private repositories and those public
repositories for which the feature is enabled. To have the feature
enabled for a public repository, please email us at
support#travis-ci.com indicating which ones. Push access to the
repository is also required.
I have found Travis are quite quick to respond but you'll also need to set up your commandline client:
Travis commandline client
So, after a lot of hassle and lots of debugging sessions on Travis CI builds, I figured out the way to solve this issue. Apparently, the default android tool-chain searches for NDK in its SDK directory. As it was not able to find that, it was complaining for the NDK. So, I had to use the Default tool chain to get the NDK. Below is a snapshot of my .travis.yml file which points to the changes that I made to resolve this issue.
To find the answer why I added tools twice, you can refer to this link. Refer to below image to figure out which portion of the Doc to refer for the answer.
So, as it's mentioned in the Travis CI documentation, when we want to build an Android Project with SDK level 24, we need to use the tools options twice in the yml script.
And then as I was using ndk-build to build my native files, I just had to add below part in the yml script.
# Configurations to set up Android NDK
before_install:
- echo y | sdkmanager "ndk-bundle"
One thing to remember. I was using C language for native project. If you are using C++, then you might need to install Cmake for that. Below is the code for that --
before_install:
- echo y | sdkmanager "ndk-bundle"
- echo y | sdkmanager "cmake;3.6.4111459" # (Check the Cmake version you want to use)

Travis: how to know android sdk/ndk path?

My android project is built with Ant and i have to edit ant.properties manually file to pass sdk.path variable pointing to android sdk directory. i'm going to change it to get sdk path from environment variable to make build possible on Travis CI. What is android sdk variable for this?
Also i have some jni code to be built with android ndk, so the similar question - what is env variable for android ndk on Travis?
Don't use the Travis's Android support; it uses the old 'android' CLI instead of the new sdkmanager CLI that supports installing the NDK. Do something like:
before_install:
- cd $HOME
- wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip -O $HOME/android-sdk.tgz
- mkdir android
- unzip android-sdk.tgz -d android/sdk
- export PATH=$PATH:$HOME/android/sdk/tools:$HOME/android/sdk/tools/bin
- cd build/<your-build-directory>
And then in the 'install' section:
install:
- echo y | sdkmanager 'ndk-bundle'
- echo y | sdkmanager 'cmake;3.6.3155560'
- export ANDROID_HOME=$HOME/android/sdk
- export ANDROID_NDK_HOME=$HOME/android/sdk/ndk-bundle
You can use the sdkmanager to install anything else you need. The benefit over the other answer is that this will grab the latest version of the NDK.
Finally, then you can set the environment variables ANDROID_HOME and ANDROID_NDK_HOME, and pass it to your specific environment.
Hope it helps.
Travis seems to provide Android support in beta. Android SDK can be found in /usr/local/android-sdk. However it seems that Android NDK is not provided and can't be found in /usr/local/android-ndk. The simple (and expensive walkaround for Travis) is to download/extract/use it right while building like this:
before_script:
- export NDK_VERSION=r10e
- curl -L http://dl.google.com/android/ndk/android-ndk-${NDK_VERSION}-linux-x86_64.bin -O
- chmod u+x android-ndk-${NDK_VERSION}-linux-x86_64.bin
- ./android-ndk-${NDK_VERSION}-linux-x86_64.bin > /dev/null
- rm android-ndk-${NDK_VERSION}-linux-x86_64.bin
- export ANDROID_NDK_HOME=`pwd`/android-ndk-${NDK_VERSION}
- export PATH=${ANDROID_NDK_HOME}:${PATH}
Feel free to comment this solution if you have a better one.
You can export the Android variables using this command as well as Clive Lee's method
env:
global:
- ANDROID_HOME=$HOME/android/sdk
- ANDROID_NDK_HOME=$HOME/android/sdk/ndk-bundle

Installation is not happening according to Docker file

I am running a calabash-android test using docker. When I build the container with my docker file it seems like nothing executing except the first line. When I check whether ruby installed or not it shows the ruby version. Apart from that nothing is working. I am adding the docker file structure here.
############################################################
# Docker file to run Calabash for android automation testing.
############################################################
FROM ruby:2.1-onbuild
# install Android SDK dependencies
RUN apt-get install openjdk-7-jdk
# Install android sdk
RUN wget http://dl.google.com/android/android-sdk_r23-linux.tgz
RUN tar -xvzf android-sdk_r23-linux.tgz
RUN mv android-sdk-linux /usr/local/android-sdk
RUN rm android-sdk_r23-linux.tgz
# Install Android tools
RUN echo y | /usr/local/android-sdk/tools/android update sdk --filter platform,tool,platform-tool,extra,addon-google_apis-google-19,addon-google_apis_x86-google-19,build-tools-19.1.0 --no-ui -a
#install calabash-android
RUN gem install calabash-android
ENV ANDROID_HOME /usr/local/android-sdk
ENV ANDROID_SDK_HOME $ANDROID_HOME
ENV PATH $PATH:$ANDROID_SDK_HOME/tools
ENV PATH $PATH:$ANDROID_SDK_HOME/platform-tools
ENV JAVA_HOME /usr/lib/jvm/java-7-oracle
I have followed this link to implement the Docker file. Since this is for the first time I am setting up docker for android haven't the faintest idea whether it is proper or not. Someone please help to fix the issue. All kinda helps are appreciated.
I get this response for the docker build
Step 0 : FROM ruby:2.1-onbuild
# Executing 4 build triggers
Trigger 0, COPY Gemfile /usr/src/app/
Step 0 : COPY Gemfile /usr/src/app/ Gemfile: no such file or directory
First, as long as the docker build does not execute all the steps, it is perfectly expected to not see anything installed.
Second, the ONBUILD directives from the ruby:2.1-onbuild are made to complete the image when building a new one from said image.
As I mention before, you can try first using
FROM ruby:2.3.0
That does not require extra onbuild trigger.

How to setup NDK on circleci for android app or lib project?

I have an Android lib project that has some C code that it depends on. In order for it to compile it needs to run compileNdk... task.
Setting up the NDK locally is pretty straightforward. However, getting it to work with circleci is not so straightforward. The circleci docs have a good amount of info on how to install the android SDK properly but there is nothing on how to properly install NDK on circleci.
What is the best way to install the Android NDK on circleci so it can successfully build/compile with my continuous integration setup?
CircleCI actually installs the NDK. It can be referenced by using the $ANDROID_NDK environment variable.
They explain this at the end of the dependencies section here https://circleci.com/docs/android
For anyone looking now, at the time of writing, CircleCI still does not bundle the NDK in the 14.04 environment.
However, you can add it manually and cache it
dependencies:
cache_directories:
- ~/android-ndk-r11c
pre:
- if [[ ! -e ~/android-ndk-r11c ]]; then wget http://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip && unzip -d ~ android-ndk-r11c-linux-x86_64.zip; fi
And add the environment vars manually:
machine:
environment:
ANDROID_NDK: $HOME/android-ndk-r11c
ANDROID_NDK_HOME: $ANDROID_NDK
PATH: $PATH:$ANDROID_NDK
UPDATE: circleci now installs NDK for you.
The best solution I have found so far is to install the NDK via wget and run the bin file. It also requires setting up an environment variable for ANDROID_NDK_HOME.
Here is a sample of what I have successfully running on circleci.
circle.yml
machine:
environment:
ANDROID_HOME: /home/ubuntu/android
ANDROID_NDK_HOME: /home/ubuntu/android/android-ndk
dependencies:
cache_directories:
- ~/.android
- ~/android
override:
- ./install-dependencies.sh
install-dependencies.sh
if [ ! -e $DEPS ]; then
... &&
wget http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin -O $ANDROID_HOME/android-install-ndk.bin &&
chmod a+x $ANDROID_HOME/android-install-ndk.bin &&
cd $ANDROID_HOME && $ANDROID_HOME/android-install-ndk.bin &&
mv $ANDROID_HOME/android-ndk* $ANDROID_HOME/android-ndk
touch $DEPS
fi

Build Android Studio app via command line

I want to build an Android Studio app (the Gradle build system), but I want to do this via the command line.
Android Studio automatically creates a Gradle wrapper in the root of your project, which is how it invokes Gradle. The wrapper is basically a script that calls through to the actual Gradle binary and allows you to keep Gradle up to date, which makes using version control easier. To run a Gradle command, you can simply use the gradlew script found in the root of your project (or gradlew.bat on Windows) followed by the name of the task you want to run. For instance, to build a debug version of your Android application, you can run ./gradlew assembleDebug from the root of your repository. In a default project setup, the resulting apk can then be found in app/build/outputs/apk/app-debug.apk. On a *nix machine, you can also just run find . -name '*.apk' to find it, if it's not there.
there are two build types to build your application using the Gradle build settings: one for debugging your application — debug — and one for building your final package for release — release mode.
Building in Debug Mode
First Navigate to Android studio project Root folder using CMD
run this command gradlew.bat assembleDebug
Output window look like this
Build signed apk in Release Mode
Edit the build.gradle file to build your project in release mode:
android {
...
defaultConfig { ... }
signingConfigs {
release {
storeFile file("myreleasekey.keystore")
storePassword "password"
keyAlias "MyReleaseKey"
keyPassword "password"
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}}
run this command gradlew.bat assembleRelease
Try this (OS X only):
brew install homebrew/versions/gradle110
gradle build
You can use gradle tasks to see all tasks available for the current project. No Android Studio is needed here.
1. Install Gradle and the Android SDK
Either
Install these however you see fit
Run ./gradlew, or gradlew.bat if on Windows
chmod +x ./gradlew may be necessary
From this point onwards, gradle refers to running Gradle whichever way you've chosen.
Substitute accordingly.
2. Setup the Android SDK
If you've manually installed the SDK
export ANDROID_HOME=<install location>
You may want to put that in your ~/.profile if it's not done automatically
Accept the licenses: yes | sdkmanager --licenses
sdkmanager can be found in $ANDROID_HOME/tools/bin
sdkmanager may have to be run as root
Try running gradle
If there are complaints about licenses or SDKs not being found, fix the
directory permissions
chown -R user:group $ANDROID_HOME
If you're reckless and/or the only user: chmod 777 -R $ANDROID_HOME
3. Building
gradle tasks lists all tasks that can be run
:app:[appname] is the prefix of all tasks, which you'll see in the Gradle
logs when you're building
This can be excluded when running a task
Some essential tasks
gradle assemble: build all variants of your app
Resulting .apks are in app/[appname]/build/outputs/apk/[debug/release]
gradle assembleDebug or assembleRelease: build just the debug or release versions
gradle installDebug or installRelease build and install to an attached device
Have adb installed
Attach a device with USB debugging and USB file transfer enabled
Run adb devices, check that your device is listed and device is
beside it
Automatically build and install upon changes
This avoids having to continuously run the same commands
gradle -t --continue installDebug
-t: aka --continuous, automatically re-runs the task after a file is changed
--continue: Continue after errors. Prevents stopping when errors occur
Run gradle -h for more help
You're likely here because you want to install it too!
Build
gradlew
(On Windows gradlew.bat)
Then Install
adb install -r exampleApp.apk
(The -r makes it replace the existing copy, add an -s if installing on an emulator)
Bonus
I set up an alias in my ~/.bash_profile, to make it a 2char command.
alias bi="gradlew && adb install -r exampleApp.apk"
(Short for Build and Install)
Cheatsheet for running Gradle from the command line for Android Studio projects on Linux:
cd <project-root>
./gradlew
./gradlew tasks
./gradlew --help
Should get you started..
I faced the same problem and seems that there have been many changes by google.
I can tell you the steps for installing purely via command line from scratch.
I tested it on Ubuntu on 22 Feb 2021.
create sdk folder
export ANDROID_SDK_ROOT=/usr/lib/android-sdk
sudo mkdir -p $ANDROID_SDK_ROOT
install openjdk
sudo apt-get install openjdk-8-jdk
download android sdk
Go to https://developer.android.com/studio/index.html
Then down to Command line tools only
Click on Linux link, accept the agreement and instead of downloading right click and copy link address
cd $ANDROID_SDK_ROOT
sudo wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
sudo unzip commandlinetools-linux-6858069_latest.zip
move folders
Rename the unpacked directory from cmdline-tools to tools,
and place it under $ANDROID_SDK_ROOT/cmdline-tools,
so now it should look like: $ANDROID_SDK_ROOT/cmdline-tools/tools.
And inside it, you should have: NOTICE.txt bin lib source.properties.
set path
PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin
This had no effect for me, hence the next step
browse to sdkmanager
cd $ANDROID_SDK_ROOT/cmdline-tools/tools/bin
accept licenses
yes | sudo sdkmanager --licenses
create build
Finally, run this inside your project
chmod 777 gradlew
sudo ./gradlew assembleDebug
This creates an APK named -debug.apk at //build/outputs/apk/debug
The file is already signed with the debug key and aligned with zipalign,
so you can immediately install it on a device.
FINAL STEPS
Here are the final steps. Make 2 .sh files with these contents. Use chmod 777 before on both. No sudo required.
Download_APK_Code_NOSUDO4.sh
# Don't forget to do chmod 777 Download_APK_Code_NOSUDO2.sh
#!/bin/bash
if [ -d "camera-samples" ]; then
echo "############################# Deleting older code base. ######################################"
rm -rf camera-samples
fi
echo "########################### Download Source Code: Start ... #####################################"
git clone git://git.quicinc.com/camera-samples -b iot-concam-apk.lnx.1.1
echo "########################## Download Source Code: Done . . . ####################################"
Build_App_NOSUDO4.sh
# Don't forget to do chmod 777 Build_App_NOSUDO2.sh
#!/bin/bash
currentDir=$(pwd)
export ANDROID_SDK_ROOT=$(pwd)
# echo "############################################ Install JDK ... ################################################"
# apt-get install openjdk-8-jdk
if [ -e "commandlinetools-linux-6858069_latest.zip" ]; then
echo "############################# Deleting older zip file. ######################################"
rm -rf commandlinetools-linux-6858069_latest.zip
fi
echo "########################################### Download Command Line Tools .. ###################################"
wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
echo "########################################### Download Command Line Tools Done .. ##############################"
if [ -d "cmdline-tools" ]; then
echo "############################# Deleting older cmdline-tools. ######################################"
rm -rf cmdline-tools
fi
echo "########################################### Unzip Command Line Tools Start .. #################################"
unzip commandlinetools-linux-6858069_latest.zip
echo "########################################### Unzip Command Line Tools Done .. #################################"
echo "########################################### Creating Directory Structure .. #################################"
mv cmdline-tools tools
mkdir cmdline-tools
cp -r tools cmdline-tools/
rm -rf tools/
PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin
echo "########################################## Updated Path : $PATH ###############################################"
cd $ANDROID_SDK_ROOT/cmdline-tools/tools/bin
echo "########################################## Accept All Licenses .. #############################################"
yes | sdkmanager --licenses
cd $currentDir/camera-samples/Camera2Video
echo "sdk.dir = $ANDROID_SDK_ROOT" > local.properties
echo "######################################## Building APK . . . #################################################"
chmod 777 gradlew
./gradlew assembleDebug
echo "####################################### Building APK Done. . . ############################################"
echo "##################################### APK generated here: $currentDir/app/build/outputs/apk/debug/app-debug.apk ###################################"
##########################################################
Run these commands.
chmod 777 Download_APK_Code_NOSUDO4.sh
chmod 777 Build_App_NOSUDO4.sh
./Download_APK_Code_NOSUDO4.sh
./Build_App_NOSUDO4.sh
REFERENCES
https://gist.github.com/guipmourao/3e7edc951b043f6de30ca15a5cc2be40
Android Command line tools sdkmanager always shows: Warning: Could not create settings
"Failed to install the following Android SDK packages as some licences have not been accepted" error
https://developer.android.com/studio/build/building-cmdline#sign_cmdline
///////////////////////////////////
WINDOWS
Here are the steps for Windows via Powershell. Tested on 6th March 2021. You can start completely from scratch.
Prerequisites
Download git
Install JDK. I used jdk-8u281-windows-x64.exe
Make a file DownloadAndBuild.ps1 with these contents.
$location = Get-Location
if (Test-Path "$location\camera-samples") {
Write-Host "########################### Deleting older code base: Start. ################################"
Remove-Item -Force -Recurse -Path "$location\camera-samples"
Write-Host "########################### Deleting older code base: Done. #################################"
}
Write-Host "########################## Download Source Code: Start. #####################################"
git clone https://source.codeaurora.org/quic/la/camera-samples -b iot-concam-apk.lnx.1.1
Write-Host "########################## Download Source Code: Done. ####################################"
if (Test-Path "$location\commandlinetools-win-6858069_latest.zip") {
Write-Host "########################### Deleting older zip file: Start. ################################"
Remove-Item -Force -Recurse -Path "$location\commandlinetools-win-6858069_latest.zip"
Write-Host "########################### Deleting older zip file: Done. #################################"
}
Write-Host "########################## Download Command Line Tools: Start. #####################################"
$client = new-object System.Net.WebClient
$client.DownloadFile("https://dl.google.com/android/repository/commandlinetools-win-6858069_latest.zip","commandlinetools-win-6858069_latest.zip")
Write-Host "########################## Download Command Line Tools: End. #####################################"
if (Test-Path "$location\cmdline-tools") {
Write-Host "########################### Deleting older folder: Start. ################################"
Remove-Item -Force -Recurse -Path "$location\cmdline-tools"
Write-Host "########################### Deleting older folder: Done. #################################"
}
Write-Host "########################## Extract Command Line Tools: Start. #####################################"
Expand-Archive "$location\commandlinetools-win-6858069_latest.zip" -DestinationPath "$location"
Write-Host "########################## Extract Command Line Tools: End. #####################################"
Write-Host "########################## Create Directory Structure: Start. #####################################"
Rename-Item -Path "$location\cmdline-tools" -newName "$location\tools"
New-Item -ItemType Directory -Force -Path "$location\cmdline-tools"
Move-Item -Path "$location\tools" -Destination "$location\cmdline-tools"
Write-Host "########################## Create Directory Structure: End. #####################################"
Write-Host "########################## Accept Licenses: Start. #####################################"
Set-Location -Path $location/cmdline-tools/tools/bin
for($i=0;$i -lt 100;$i++) { $response += "y`n"}; $response | ./sdkmanager.bat --licenses
Write-Host "########################## Accept Licenses: End. #####################################"
Write-Host "########################## Build APK: Start. #####################################"
Set-Location -Path $location/camera-samples/Camera2Video
$Env:ANDROID_SDK_ROOT = $location
.\gradlew assembleDebug
Write-Host "########################## Build APK: End. #####################################"
Write-Host "##################################### APK generated here: $location/camera-samples/Camera2Video/app/build/outputs/apk/debug/app-debug.apk ###################################"
PAUSE
Right-click and run via Powershell.
This will download an Android project via git, install the SDK and build the Android App.
Edit as per your convenience.
For Mac use this command
./gradlew task-name
MacOS variant
./gradlew <moduleName>:assemble<build_variant>
//e.g
./gradlew <moduleName>:assembleDebug
*./ means current directory
[More info]
Only for MAC Users
Extending Vji's answer.
Step by step procedure:
Open Terminal
Change your directory to your Project(cd PathOfYourProject)
Copy and paste this command and hit enter:
chmod +x gradlew
As Vji suggested:
./gradlew task-name
DON'T FORGOT TO ADD .(DOT) BEFORE /gradlew
Official Documentation is here:
To build a debug APK, open a command line and navigate to the root of your project directory. To initiate a debug build, invoke the assembleDebug task:
gradlew assembleDebug
This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/.
note, you can also do this within Android Studio by clicking the gradle window, and then the 'elephant' button. This will open a new window called "run anything" (can also be found by searching for that name in 'search everywhere') where you can manually type any gradle command you want in. Not "quite" command line, but often provides more of what I need than windows command line.
This allows you to give optional params to gradle tasks, etc.
enter code hereCreate script file with below gradle and adb command, Execute script file
./gradlew clean
./gradlew assembleDebug
./gradlew installDebug
adb shell am start -n applicationID/full path of launcher activity
Adding value to all these answers,
many have asked the command for running App in AVD after build sucessful.
adb install -r {path-to-your-bild-folder}/{yourAppName}.apk

Categories

Resources