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

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.

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.

Android with visual studio 2017 - build.gradle vs build.gradle.template

So I'm trying to build an Android app using Visual Studio. I started with a project created from the 'New Project' wizard ('Basic Application (Android, Gradle)'). I'm having trouble understanding how the build.gradle and build.gradle.template files relate to each other. The build.gradle file doesn't even show in the VS solution explorer until I enable 'show all files'. And when I make changes to build.gradle, they seem to be overwritten (sometimes?) upon build. Should I only edit build.gradle.template? What build step or tool processes this file to create the final build.gradle? Does the same apply to AndroidManifest.xml.template?
And what about gradle-wrapper - is gradle-wrapper.properties the same as gradle.properties? (I had to add the location of my JDK in there to get builds from the command line, outside VS, to work - so I just created my own gradle.properties but now I'm not sure if there are multiple parts doing the same thing, potentially stepping on each other).
The build.grade is generated by Visual Studio, from the build.gradle.template before it actually runs Gradle. This is true for the AndroidManifest.xml.template as well.
You should not edit the .gradle or .xml file itself and preferably not include it in your source control.
As for the wrapper, I can't really answer.

Module not specified after opening project from another computer

I keep my projects in my Dropbox folder. I installed Android Studio on my laptop and I tried to open the Project. All java files had a red circle which I managed to fix by marking the Directory as Sources Root. When I try to run the application, the Edit configuration window pops up with a sign at the bottom saying that Module is not specified, in red. There is no module I can select in the appropriate combobox. Syncing project with grandle files has no effect and importing the project instead of opening it makes things even worse. At the Projects side tab, by selecting the Android option, I can only see the Grandle Scripts structure and not the project files. The project files are visible when I select the Project option from the combobox.
The project cannot even open at the original computer anymore. I am new to Android and I have spent a lot of time developing this project. What can I do to reverse the situation?
You have to change some gradle properties.
First you open android studio and create a new project. Then change your old project's all gradle properties according to new project. like bellow--
Go to your build.gradle(Module:app) script and change the gradle version like compile 'com.android.support:appcompat-v7:25.3.1' to your current version.
Go to your build.gradle(Project:your app) script change this line classpath 'com.android.tools.build:gradle:2.3.0' to your current version.
Finally you have to change gradle-wrapper.properties(Gradle Version) distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
to your current version
Now sync your project, I hope it will working fine.

Android studio: this project is not gradle based project

I have one project which was initially in eclipse, then i managed somehow to convert it to gradle and everything was working fine in Android Studio.
But then i didn't work some time with the project and after few months when i returned to project i am surprised that Android Studio has problems with this project.
When i selected "Android" from top left dropdown in AS, where you should see the project as Android, i saw no files, then i did something and now i see there one empty folder Java.
If i hit button "sync project with gradle files" AS says message as posted in name of question, but it is gradle based project.. there are gradle files etc.
Do you someone know why is this problem? Why it should stop work like this?
Thank you
Make sure you open the project from its root directory. i.e. the directory which contains the top level build.gradle file.
The missing top level gradle file is what causes this error.
For native Flutter Projects:
Note that this error will also appear if you "sync your project with Gradle files " in the root directory. Gradle works only in your android directory (flutter_name/android).
Configure Gradle version
I got this error because i wanted to change some build values like the Gradle version and the Gradle plugin version (and other build values ex. kotlin):
In your current project: File>Open
Select directory: user/StudioProjects/flutter_name/android
Open directory in a new window
After it is opened it will load some packages (see right bottom), which will take some time.
Under File>Project Structure Project you can set the gradle version and under Modules variables of your build
Now you can sync your project with Gradle files or at least read out the error messages, that come with your configuration
After configuration, you might need to restart your project with File>Invalid Caches/Restart....
That worked for me:
copy the file build.gradle
drop the copied file build.gradle in
your app/project folder .
My project stopped showing all of sudden and already had build.gradle file.
I just reopened it via File > Open.

How to run the 'gradle init' task in Eclipse Buildship plugin?

I want to use Gradle for my Android project, and I use Eclipse (rather than Android Studio). My web-search pointed me to Eclipse's Gradle Plugin called Buildship. I downloaded and installed it following this guide.
My need is to convert my Android project in my Eclipse workspace into something that works with Gradle build system. So following this section of the guide mentioned, I added Gradle support to my project. But I still can not see a build.gradle file in my project. I did refresh the project.
So what do I do to get a build.gradle file in my project?
*The guide I linked to says, *
Run the 'gradle init' task to create the initial Gradle files, in case
you do not have them yet.
but I can't figure out how to run the gradle init task.
In the "Gradle Tasks" panel, expand the node of your project. Then expand the "build setup" node. Right click on "init" and select "Run Gradle Tasks".
Then in the project explorer, right click on your project and select "Gradle", then select "Refresh Gradle Project". And voila! You must be able to see your build.gradle now.
Go to windows-->Show View-->Gradle Tasks. In this view you will be able to see your project.Expand build setup and double click "init" task.

Categories

Resources