How to do an assembleRelease for a single module in android - android

I am trying to do an assembleRelease for a single module. I have already red this Gradle build only one module, where the approach is to put on a terminal
./gradlew :nameOfModule:action(assembleRelease on this case). I need to know if I am doing it right, because it should be generating an apk but instead what I get is a .dex document.

Android studio provides an ability to do Gradle tasks via a user interface.
Push a "Gradle" button in a top right corner of the Android Studio, in a pinned window select a moduleName -> Tasks - > build -> assembleRelease
You can find a generated .apk file in %PROJECT_ROOT%/Module/name/build/outputs/apk directory.

Related

How to build specific app APK with Android Studio when the project contains multiple apps?

I try to build and run the sample helloworld/mobile in project (https://github.com/android/car-samples)
My question is about how to select the sample app directory as described in README.md:
Select a sample app directory (e.g. helloworld/mobile) in the Project Structure UI on the top left. Each sample app has two build targets, one for the mobile platform and the other for the automotive platform.
<<<<
I went through Project Structure UI, I tried different possibilities but no way,
Build menu always shows Make Module car-simples-main and when I launch Make Module, nothing happens.
Wondering if something has changed in the last Android Studio version,
I use Android Studio Chipmunk | 2021.2.1 Patch 1
Anyone can help?
Thanks.
First of all, let's understand how the git directory is structured.
The directory has the two folders car-lib/CarGearViewerKotlin and car_app_library, which are gradle projects that can be built using gradle.
How do you know?
Any folder contains gradle wrapper and a build.gradle and settings.gradle files means that they're ready to be built using gradle, and these can contain modules inside of them.
Now helloworld/mobile is a module, or you can view it as a sub-project.
How do you know?
If you open up the parent's settings.gradle file, you will see the line include ':helloworld:mobile' meaning that the directory helloworld/mobile is a sub-project or module for the top level car_app_library project.
Modules by themselves are not runnable, they need to be contained in a parent project with top-level gradle files.
Now the solution for your problem should be: open up these two as projects in Android studio individually: car-lib/CarGearViewerKotlin and car_app_library, it will create a default run configuration for each project.
You won't be able to run helloworld/mobile alone, you'll need to run the parent project car-samples/car_app_library.
However, You should technically be able to open the root directory (the git directory containing all of the projects) and creating a run configurations by hand for each project, and you should be able to run the projects using one Android Studio window opened.

It there a way to chose which build variant to build?

I have android lib module (with native implementation). When I build the app (as debug) it also build this lib module (as debug) and as a result of lib build I get .aar (as a debug). All is fine here, I try to build debug and I get debug .aar.
Then, I need to build this android lib without the whole android app, just this lib. In order to do it I open Gradle tab at the right side in Android Studio window then I found my lib name -> Tasks -> build -> assemble. And this gradle task make a build for only this lib.
Issue is that as a result I get two .aar files one debug and one release. I don't need to get two I would like to have an option to choose what to build - debug or release.
Main issue here that it takes a lot of time for build this lib in debug and in release. Because of this I would like to choose how to build and it should save a time.
So, how to do it?
Since you are building all variant it will take time so You can use android build comment ./gradlew :app:assembleDebug or ./gradlew :app:assembleRelease . Run comment in your application root folder
NB:- if you application not in app folder means submodule use corresponding folder name instead of app ./gradlew ::assembleDebug

Android Studio "Build - make project" does not create jar

I am developing an app in Android Studio for the first time, and I want the app to connect to a server that I will also develop. This server will run on the Java Runtime Environment instead of Android, but I'd prefer if I can develop it alongside the app, in the same project and IDE.
What I have done so far:
added a server folder in the root (same level as the /app folder)
added a server/src/java/main/Hello.java file to get started
added a server/build.gradle file with this content:
apply plugin: 'java'
jar {
manifest {
attributes 'Main-Class': 'Hello'
}
}
updated settings.gradle to include the server module like this:
include ':app', ':server'
The above suffices to get this working:
Executing gradle build on the command line now creates an executable server.jar.
The server code shows up in Android Studio. It is also built if I click Build - Make Project.
However, Build - Make project is for some reason only compiling Hello.java files into a .class file. It is not creating the server.jar file. Why is it not doing the same thing as a gradle build? How do I fix this?
All available gradle tasks can be explored from the "Gradle projects" tool window on the right hand side of Android Studio, though you may have to click the "refresh" button first before it shows them. The jar task should show up there, and double clicking will build the server.jar file.
Creating a jar file is not necessary to quickly launch the server from Android Studio though. Change server/build.gradle as follows:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "Hello"
After another refresh in the "Gradle Projects" tool window, this should make a "run" task available. Right-click it and click the "run ..." menu item to turn this task into a run configuration. Now the application can easily be started with the run button at the top of the IDE.

can't find unsigned APK in android studio, where is it?

So I tried run, make, assemble, from android studio on a vanilla hello world app (it's the app that it creates from the default file -> new project and I can't find the unsigned APK in the MyApplication/build folder. I can generate a signed apk going through the build menu but I can't seem to find the auto generated debug apk.
I also tried following some instructions on going through the project structure menu but I can't find a plus button that adds an artifact.
If your project has modules (e.g., an app/) module, APKs go in the module. So, I would look in app/build/outputs/apk/ (again, assuming that you have an app/ module).
You should build apk by gradle.
1.Enter the root directory of your project and command ./gradlew -v to download gradle.
![./gradlew -v][1]
[1]: http://i.stack.imgur.com/iMbGO.jpg if you download successfully, you'll see this formation.
2.command ./gradlew clean to download dependencies of gradle.
![./gradlew clean][1]
[1]: http://i.stack.imgur.com/WlWQR.jpg if successfully, you'll see this formation.
3.command ./gradlew build to build and generate apks.
Enter [Your-project]/app/build/outputs/apk, you will see app-debug.apk, app-debug-unaligned.apk, app-release-unsigned.apk.
You can use the option Build -> Analyse Apk and you can find the path of your apk

In Android Studio, building one project of a multi-project setup with Gradle, can I make it only build one of the projects?

I have a multi-project setup in Gradle and work in Android-studio. The setup contains two apps (each one has its own project directory with its own build.gradle) and some libraries shared by those apps.
The directory structure looks like this:
/workspace/
/workspace/app1/
/workspace/app2/
/workspace/app3/
/workspace/library1/
/workspace/library1/
When I build from the command line I can limit the build to only one of the apps via
gradle assembleDebugApp1
When I build from within Android Studio, it seems to build all projects that have a build.gradle file and are inside of workspace.
In Android Studio, when I run Build->Make Project, I see on the bottom what gradle does:
Gradle build using tasks: [:app1:assembleDebug, :app2:assembleDebug, library1:bundleDebug, (...)].
I would like it to only run the assemble task for my "current project".
I'm new to AndroidStudio, so maybe the question is : How do I set the "current project'?
How do I tell Android Studio to only build what I need for app1?
Edit based on replies:
I do want to run gradle via make so it does give feedback back to the IDE, because I'd like to see the "Make Messages" window:
Open Gradle tasks tab and select task to run. You can select a task from subprojects.
On command line:
gradle :app1:assembleDebug
I'm not sure if there is an "official" way of handling this yet but I got around it by creating a new "Run Configuration" and replacing the default "Build" option in the "Before Launch" section with my own command that calls Gradle with the relevant command line options.

Categories

Resources