How to build a 'release' APK in Android Studio? - android

I am trying to build an APK that I can upload to the Play Store.
When I select Build|Generate Signed APK... in Android Studio (version 0.3.1), I am directed to a link on how to properly set up the signing process in the "gradle build scripts":
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Signing-Configurations
Unfortunately, after checking that page I'm at a loss as to what file to edit and what to put in it - I'm coming from a Visual Studio background, so lazily expect stuff to 'just work' :).
(After OK'ing Android Studio's warning message, A.S. brings up a Generate Signed APK Wizard, which I went through, passing my key's details. The resulting APK was rejected by the Play Store for having a key with a too-soon expiry-date).
I also tried bringing up the Android Studio Terminal window and running 'gradle', as instructed in the above message, but this command was not found. So as an aside, since perhaps running the command might do something useful, how would I run gradle?
I found a 'Gradle' window in the A.S. IDE, and tried building the assembleRelease target found in that window. However, the Run window output just shows "Executing external task 'assembleRelease'...".

Follow these steps in the IDE: Build -> Generate Signed APK -> Create new...
Then fill up "New Key Store" form. If you wand to change .jnk file destination then chick on destination and give a name to get Ok button. After finishing it you will get "Key store password", "Key alias", "Key password"
Press next and change your the destination folder.
Then press finish, thats all. :)

Click \Build\Select Build Variant... in Android Studio.
And choose release.

AndroidStudio is alpha version for now. So you have to edit gradle build script files by yourself. Add next lines to your build.gradle
android {
signingConfigs {
release {
storeFile file('android.keystore')
storePassword "pwd"
keyAlias "alias"
keyPassword "pwd"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
To actually run your application at emulator or device run gradle installDebug or gradle installRelease.
You can create helloworld project from AndroidStudio wizard to see what structure of gradle files is needed. Or export gradle files from working eclipse project. Also this series of articles are helpfull http://blog.stylingandroid.com/archives/1872#more-1872

Related

Cause: buildOutput.apkData must not be null

My android application using Kotlin is throwing this exception when I try to Run 'app' in the emulator o in my cellphone. When I build my project it runs well, with no errors.
I am using:
SDK 28 (Android 9.0 (Pie))
Gradle 5.1.1
Gradle Plugin 3.5.0-alpha03
Kotlin 1.3.10
Java 1.8.0_151
OSX 10.13.2
org.gradle.internal.exceptions.LocationAwareException: buildOutput.apkData must not be null
at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:99)
at org.gradle.initialization.exception.DefaultExceptionAnalyser.collectFailures(DefaultExceptionAnalyser.java:65)
at org.gradle.initialization.exception.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:39)
at org.gradle.initialization.exception.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:29)
at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:194)
at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:141)
...
Caused by: java.lang.IllegalStateException: buildOutput.apkData must not be null
at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion$load$2.invoke(EarlySyncBuildOutput.kt:103)
at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion$load$2.invoke(EarlySyncBuildOutput.kt:67)
at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:174)
at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:691)
at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:721)
at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:712)
...
Click Build -> Clean Project
Then Build -> Make Project
Tested on gradle 3.5.0-alpha3, -alpha5 and 3.4.0 (project gradle)
classpath 'com.android.tools.build:gradle:3.5.0-alpha03'
For Android Studio 3.5 & 3.6 Update (APK signed issue)
Step 1: I have resolved this issue by modifying the Destination Folder location.
Before
c:\user\folder\project\app
After
c:\user\folder\project\apk
For Android Studio 3.4 Update.
Step 1: After update Android Studio 3.4 you need to add all the dependency that used in your module or library in your app-level build.gradle.
Step 2: Clean Project(Build > Clean Project)
Step 3: Rebuild Project(Build > Rebuild Project)
Now, Your Project will compile Perfectly.
FOR Android Studio 3.5 | 3.6
debug builds finish without any error. Creating a signed .apk leads to the same error
buildOutput.apkData must not be null
the Simple solution that I found is. During the signing of the apk after entering the signing credentials when you navigate to the next screen then it will ask for the destination folder just change the default path.
Let's assume the current destination path is
c:\user\folder\project\app
change it to
c:\user\folder\project\
then it will generate the signed apk successfully.
I was getting this error also, when trying to "Generate Signed APK" for my release version.
I tried all of the above methods, unfortunately none worked for me.
What worked, was generating first the debug signed version of the app, and then generating again the release one.
I do not know what exactly changed or what the original problem was, but it worked. I hope it will help you too, because this error is quite annoying...
Cleaning the project didn't help me but manually deleting all the auto-generated build folders in all modules helped.
Updating to Android Studio 3.4.?, i get the message
Cause: buildOutput.apkData must not be null
looking for an answer i found the procedure:
Build -> Clean Project
but it doesn´t worked, i know that this procedure will delete the content into the /build directory but for my experience it doesn´t work in all cases, so i tried the "raw" way, deleting the directory:
/app/build/
then i rebuild the project and it worked.
All the solutions didn't work with me
Android Studio V 3.5
Android gradle plugin V 3.4.2
Gradle Version V 5.1.1
Clean the project
Restart Android Studio + Invalidate Caches
Delete the build, debug, and releases folder
Make project
Generate signed APK
Reference
I tried above multiple solutions but nothing has happened then I found this
this and worked for me
deleting debug/output.json and release/output.json solved my problem
Now I am able to generate apk
I've tried many things to solve the issue, but nothing helped. I get this error when trying to generate a signed apk.
Downgrading to older versions of Android Studio helped (3.4.2) worked, however this is not the solution.
The 'Clean Project' function in AS does not clean the place where your generated apk is created and there is one file that may be blocking the whole procedure: output.json
Try removing output.json from .../app/projectname/release/output.json
I was using Android Studio 3.5 beta 2 and I was having the exact same error but only on my release build. After trying every other solution I found, the only way I was able to compile again was to go back to Android Studio 3.4.
It works for me:
delete build folder from your project manually.
in terminal of android studio type this command
if windows user
gradlew clean build
if linux user
./gradlew clean build
This issue is happens usually when you are running multiple android studio window with different projects.
The solution is
choose project than delete .gradle and build folders
than clean and rebuild the project.
please ref screen shot attached
Just change the Apk release/debug location.
EX:
/home/sanaebadi/Desktop
after change :
/home/sanaebadi/apk
The solution for me was to delete all files and folders from the apk output folder.
I had this problem when creating a signed apk for a "production" flavor and the output.json in the "feature" output folder causes the problem -> Android Studio 3.6 Canary 7 showed me the correct error message.
It is also working now for AS 3.5 stable with Gradle Plugin 3.5.0.
All the solutions didn't work with me
In my case from AndroidStudio 3.4+ update to 3.5.
And finally I solve it by modify 'Destination Folder' to "app/build/outputs/apk"
detail pic
the only solution that works for me is using in my root gradle
classpath 'com.android.tools.build:gradle:3.3.0'
what i've tried :
- clear all build folder manually
- invalidate cache
but none of these is work
PS: i'm using android studio 3.5 btw
Update :
just like #Vishrut Mavani, changing the destination folder of your release version is work
The solution :-
1- Build -> Clean Project didn't help
2-Build -> Make Project didn't help
3- restart android studio didn't help
4- Manually remove Build folder from app and project didn't help
the only solution for me was to remove all old builds from destination folder
Manually delete all the exiting build variant folder as well build folder in project folder worked for me.
Usually this issue happen on updating android Studio V3.4 to V3.5.
Try to delete debug/output.json and release/output.json files.
Then Try these steps:
Step 1: Clean Project(Build > Clean Project)
Step 2: Rebuild Project(Build > Rebuild Project)
I have android studio 3.5.1 . For me below steps are worked
File -> Invalidate Caches/Restart
After android studio restarted click on Build -> Clean project
Then Build -> Rebuild Project
In my case build and launch project with different build configs was successful. But generating signed apk throws error Cause: buildOutput.apkData must not be null on the other hand apk was generated and Build Output toggle view prints BUILD SUCCESSFUL. Manual installation ends with message App not installed. My fault was using compileSdkVersion 'android-P' and after changing to compileSdkVersion 28 all goes well.
I've tried all solutions and non of them helped! finally after many trying, I figured it out, just follow the tips:
copy your signature keystrok (that you use to release) inside yourProject/app/
gradle.properties (modify values related to your own key):
MYAPP_RELEASE_STORE_FILE=KEYSTROK_NAME
MYAPP_RELEASE_KEY_ALIAS=KEY_ALIAS
MYAPP_RELEASE_STORE_PASSWORD=R_PASS
MYAPP_RELEASE_KEY_PASSWORD=K_PASS
android.enableR8=true
app level build.gradle (inside android):
signingConfigs{
release{
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
configurations {
cleanedAnnotations
compile.exclude group: 'org.jetbrains' , module:'annotations'
}
app level build.gradle (inside buildTypes):
release {
manifestPlaceholders = [analytics_deactivated: "false"]
minifyEnabled true
signingConfig signingConfigs.release
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
5. finally this command:
mac: ./gradlew clean assemble_YOUR_FAVOR_Release
win: gradlew clean assemble_YOUR_FAVOR_Release
where _YOUR_FAVOR_ is your optional favor, if you are not using any favor, just simply use assembleRelease instead of assemble_YOUR_FAVOR_Release
This issue happens after update my Android studio v3.4 to v3.5
Now, it is working fine
I fixed this issue by deleting debug/output.json and release/output.json files
Android Studio 3.5
compilesdkVersion 28
apk generating working
I was also annoyed by the same bug. But changing my Signed apk destination from c/users/project/app to c/users/project worked for me.
1- Delete all generated app bundles (.aab) and APKs for all variants.
2- Delete the build folder
3- clean project
Generate Signed APK for debug,
and then you can generate signed APK for release.
Seems cleaning the project may resolve the issue, but for me it worked like this.
File->sync project with gradle files.
AS 4.0.1 (installed via snap)
Ubuntu 18.04 lts
configuring builds via build variant.
Combinations of invalidate cache / build / clean etc didnt help on their own, the only thing that helped was to switch build the active build variant back to armDebug and clean / rebuild after that.
Once I switched back to the desired variant I could build correctly.
enter code hereIf your using different build variants, Select the specific folder to generate signin apk file. When you are trying to generate signin apk flow, you can change the path. For me, this worked.
In my case, the path was pointing to e: drive and other solutions didn't work for me.
I did:
Change the path
The path must be in the c: drive
It solved the problem

How can I use Gradle to build Android applications from the command line

I'm just trying to adapt to Android Studio, and I'm not enjoying it much.
A cursory glance at the Gradle site suggests that an aim is to be able to make the same build from the command-line as the IDE. If so, presumably it's possible to use Gradle to build Android Studio projects wtihout running Android Studio.
How can I do this? Are there any online examples?
Building in Debug Mode
For immediate application testing and debugging, you can build your application in debug mode and immediately install it on an emulator. In debug mode, the build tools automatically sign your application with a debug key and optimize the package with zipalign.
On Windows platforms, type this command:
> gradlew.bat assembleDebug
On Mac OS and Linux platforms, type these commands:
$ chmod +x gradlew
$ ./gradlew assembleDebug
To see a list of all available build tasks for your project, type this command:
$ ./gradlew tasks
Building in Release Mode
Build signed and aligned
If you would like, you can configure the Android build script to automatically sign and align your application package. To do so, you must provide the path to your keystore and the name of your key alias in your modules's build.gradle file. With this information provided, the build will prompt you for your keystore and alias password when you build using the release build type and produce your final application package, which will be ready for distribution.
To specify your keystore and alias, open the module build.gradle file (found in the root of the module directory) and add entries for storeFile, storePassword, keyAlias and keyPassword. For example:
storeFile file("myreleasekey.keystore")
keyAlias "MyReleaseKey"
Save your changes. Now you can build a signed .apk in release mode:
Open a command-line and navigate to the root of your module directory.
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
}
}
}
Hope it helps

Unsigned apk generation with Android Studio doesn't work

I generated my project with Cordova, I'm using Android Studio to develop my app, I can test the app on a connected Android platform, but I'm not able to generate apk. I run Build -> Build APK the IDE says Build APK: APK(s) generated successfully. Reveal in Finder, but I cannot find anywhere the generated APK (I searched it in my filesystem).
I added a build-extras.gradle containing:
android { lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
And in select build variant I choosed debug.
Any suggestion?
Thanks

Why won't Android Studio create my AAR file in release mode

Using Android Studio, I have an Android library project which produces 'library/build/outputs/aar/MyLIB.aar" just fine in Debug mode, but does not do so in Release mode. I see no errors, just "BUILD SUCCESSFUL" in the "Gradle Console" window but no Release Mode artifact.
There was a similar question raised here, and I'm getting the same behavior as #user1624552 mentions in the link:
"gradlew clean" followed by "gradlew aR" resultd in my AAR being created and correctly placed in the directory above. But using Android Studio and the "Release Mode" Build Variant does NOT create an AAR file.
Is there something configured in the Debug variant which is not configured in the Release variant?
Thanks,
ALF
Right click the task you want and click "Run".
To get the aar, you can do the following
“View/Tool Windows/Gradle”, to open the gradle window
From gradle window, run assembly Gradle task by double-click on My_Plugin_Android/:My_Plugin/Tasks/build/assemble

Android Studio : install Release App by command line

I want to export apk file "release apk" from command line
when I run this command : gradlew installRelease
and I found this
Android Studio Task 'install Release' not found in root project ''.
Some candidates are: 'uninstall Release'.
How can I solve it?
My experience has been that the installRelease task does not become available until you define the signingConfigs in the buildTypes.release block of your build file, as shown in step 3 of Signing in Release Mode. Without signingConfigs, you will get other release tasks, such as assembleRelease, but not installRelease.
So there is no such task. You can see all available tasks calling gradlew tasks. To assemble release version of apk call gradlew assembleRelease and then using adb install it.
You may build with Android Studio Build/Generate Signed APK.... In this case you'll get .apk file in your repository. You then can use adb install .apk to install it. You'll have no changes in build.gradle file in this case.
Alternatively you may change build.gradle file as mentioned here. In this case you will have installRelease task. You may get these changes in build.gradle using Open Module Settings menu. See details in Gradle for Android and Java course from Udacity.
In my case, the installRelease option didn't show up until I deleted the line
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {

Categories

Resources