Specifying output location when assembling an Android project with Gradle via Terminal? - android

I'm trying to automate the build and upload process for a signed APK of an Android app without using Android Studio, so I'm running everything in Terminal. The first command is:
./gradlew assembleRelease
Which generates an unsigned, unaligned APK in the /APP NAME/build/outputs/apk folder. However, since APP NAME won't be the same for every app, I can't just hard code the location of the output file into the next step of signing it. Are there any arguments I can use with the gradlew command to specify an output directory and file name of my choice?

There is no such command to specify the output.But you can write a script to make this possible.As you have got the /build/outputs/app-release.apk, you can copy and rename it to everywhere you want.

you can dynamically append some script to that build file(build.gradle) to set the buildDir of any project.
for example:
allprojects {
buildDir = System.properties['user.home']+"/"+project.name;
}

Related

AAB output file name and path gradle variable

I am trying to move my aab build process from my local machine to GitHub Actions following this post and using this GitHub action. In order to do so I need the releaseDirectory. In my project, unlike the example, I have two modules in the same project, so I have been trying to determine how to get the path from the ./gradlew bundleRelease
On my local machine when I run different items from the build menu, the artifacts are written to different directories:
Build APK > app/mobile/build/outputs/apk/debug/mobile-debug.apk
Build Bundle > app/mobile/build/outputs/bundles/debug/mobile-debug.aab
Generate Signed Bundle > app/mobile/release/mobile-release.aab
Ideally I would like to have the path printed during the build process so I can see the path in the GitHub Actions output, but I cannot determine the right variables to print in the build.gradle:
println("buildDir (mobile)=${buildDir}")
seems to print:
app/mobile/build/
Is there a more complete variable for the path of an aab file? I can understand the first two might be generated, but why is the third result so different? Both modules go to the same directory under the first module's directory.

provide apk path to gradle assembleRelease crashlyticsUploadDistributionRelease

I am trying to do Beta distributions with Gradle.
The following command should do, mentioned here.
gradle assembleRelease crashlyticsUploadDistributionRelease
But my signed apk is not in default folder app/build/outputs/apk/release/.
This is placed in some other folder, let's say /deploy/apk/.
How to let the
gradle task(crashlyticsUploadDistributionRelease) know apk path? Is there any way in command line option/parameter to specify input apk path?
Regards
Annada
Mike from Fabric here. Use
ext.betaDistributionApkFilePath = "path to the universal split APK"
in your specific flavor or variant, to use the APK in the path that you've specified.

Find versionnumber and versioncode of apk generated by android studio

I know that .apk files are zip files and when we extract them can parse manifest file inorder to finding some information about the app. It is very useful for someone like me that is going to create an app-store. Actually at least I can find the version name and version code of the app.
But in the android-studio when we build a signed apk the version name and version code is not defining in the manifest file. We should define them in the build.gradle file. So now in my app-store when users upload the files how can I find the version code and version name and detect that is not same with old versions?
Just use AAPT from your path/to/your/android-sdk/build-tools/your-api-version-available/...
An example of the command execution:
aapt dump badging theuserapp.apk
And it will respond with something like:
package: name='com.blabla.theuserapp' versionCode='2000' versionName='2.0.0'
Of course, as the tool is an executable which produces a raw text output you can easily script it and parse from your favorite scripting languaje.
On GNU/Linux environment you can make a bash search.
with these steps:
-> on Studio choose terminal tab;
-> change directory to root directory of your project.
-> run this command $ find pwd -name *.apk
-> yours apk files will be listed on the screen, then you can see the directory where they are hosted

Insert File To An Existed .APK

I need to add some resource files to an existed .APK file. I wrote a program in Java Se which using ZipInputStream and ZipOutputStream to insert files into assets/myfiles and it works perfectly but when I want to install my new .APK file on my tablet it failed to install!
Is there any signature that I should add to new files and how?
Yes ofcourse you will have to sign the apk files after adding the files externally. If you want to automate the building process and add files to your apk file on building time then
What I would suggest is that
i. Try to build and sign the apk file via ant script more information can be found here:
http://developer.android.com/tools/building/building-cmdline.html
You will notice from the above link that you will have to run the command "ant release" from command line to build the project.
ii. Create a batch file (or a .sh file for linux) that will run the ant command.
ii. Then add files to the project directory for example the asset/ folder (You will have to write another program to add the files instead of the ZipStreams you already wrote).
This new program will add files to your directory and then execute your batch file which will then run the ant command.
Notice that the ant release command also signs the resulting apk file. In this way you will automate the process of adding files to your resulting apk file.
But there is one tricky part is to when you run the ant script it prompts you to enter your alias password you will have to a bit of search on how to add this password to your ant script. (Shouldn't be difficult)

Run batch file after each build in eclipse

I have a number of projects that I work on simultaneously.
Every time I build and run one of them, the apk is located as usual in the bin folder.
If I want to copy this apk to some other folder outside the project, I have to do it manually.
I created a single batch file that copies all my projects' apk files to the desired location.
Is there a way to change the output location of the bin folder to somewhere outside the project or more preferably run the batch file after each build?
NOTICE
I am using eclipse with ADT. I have tried to add a builder that executes the batch file. However, when the batch file is run, the apk file is not yet generated. I tried all combinations of options in the builder and all the possible of sequences of builders.
If you are happy just to use Eclipse whilst you are perfecting the build, then switching to the command line for the final build, then with Ant it's really easy to get what you want with very little effort or configuration.
Assumptions
1) Your sources are in an Android workspace and you will end up with two sets of binaries - one made by Eclipse, the other made by Ant will end up outside the workspace as set by a PROPERTIES file
2) You are using SDK14 or 15 (Ant changed in 14)
3) You have Ant installed and in your path - you'll need to have Ant 1.8.2 - this is not the internal one that Eclipse uses, you may have to get it from the Apache site, it's easy to install
Steps
1) Make a sample project from the command line as described in http://developer.android.com/guide/developing/projects/projects-cmdline.html
For example I used:
android create project --target 8 --name Sample15App --path c:\dev
\projects\samples\Sample15 --activity Sample15Activity --package com.me.samplefifteen
This will make a directory and some files which you will use later as a template in your projects
2) Make a sample project in your workspace from Eclipse, I made EclipseSample in one of my workspaces
3) Copy the following files from Sample15App to the root of your EclipseSample project:
build.xml
ant.properties
local.properties
4) Edit ant.properties (which is initially empty) to be like this example:
projectname=EclipseSample
workspace.dir=/dev/projects/EclipseIndigo/AndroidWorkTwo
base.dir=${workspace.dir}/${projectname}
outbasebase.dir=/dev/projects/AntBuilds
outbase.dir=${outbasebase.dir}/${projectname}
ant.project.name=${projectname}
out.dir=${outbase.dir}/bin
layout.dir=${base.dir}/res/layout
source.dir=${base.dir}/src
From this you can see that my workspace is /dev/projects/EclipseIndigo/AndroidWorkTwo
The eclipse project under this is in directory EclipseSample
I want my apks to end up in /dev/projects/AntBuilds/EclipseSample (i.e outbasebase concatenated with projectname -so for other projects you can use a very similar ant.properties file just change projectname)
5) IMPORTANT - EDIT THE build.xml
Comment out or remove the line :
<project name="Sample15App" default="help">
replace it with just
<project>
This just means it will pick up the project name from ant.properties rather than the build.xml and you can use the same build.xml in all your projects, only ant.properties need change
6) try it with "ant debug" should build the debug apks under /dev/projects/AntBuilds/EclipseSample
7) finally if you want to automate the release build (signing and password entering automatically) add lines like
key.store.password=YourPassword
key.alias.password=YourPassword
key.store=c:/users/you/yourrelease-key.keystore
key.alias=release_alias
to the ant.properties and then you just type "ant release"
If you don't add them it will tell you to sign manually and as no password entries were found in 'build.properties' (- that was what ant.properties used to be called pre SDK 14, they should have corrected this!)
You can add new Builders to your project using Project Properties->Builders->New....
One way to do this is to create an ant build (which copies the file), or just a plain old script or batch file.

Categories

Resources