How to compile backend without android app in Android Studio - android

So I have an android app with an app engine backend (App-Engine Connected Android Project). Back when I used to work in Eclipse, I could compile the backend, then generate the endpoints for android, and then work on android. But now on Android Studio I don’t seem to be able to build the server without it building the android app as well. The problem with that is my android app is not ready to compile. So how do I work on the server and compile it and deployment apart from the android app? Needless to say I am extremely new to Android Studio. But I know the eclipse workflow, which is
Work on server code (develop, compile, test)
Generate client endpoints for android

Your Android Studio Project is likely to be a multi-module project i.e. it will be having a server side app and an Android app.
Android Studio uses Gradle as its build tool and hence you have the option on working on specific Gradle tasks (clean, compile, build, etc) on each of the projects separately. You need not always launch or run the overall Build process that will try to look at dependencies and then build all the stuff.
Since you want to work on the Server app separately and make that ready, I suggest that you can run the build tasks specific to that project. In the commander view you will see Gradle tasks for each project separately and you can run that. Alternately, you can also go to the terminal and look at the tasks and/or run those separately.
For e.g. let's say that you have an Android Studio project named MyApp and it has two modules in it called app and api. The app is the Android module and api is the Server side module with Cloud Endpoints. If you visit the terminal or command line and go to the root folder you can run Gradle specific tasks for each of the modules via gradle <modulename>:<taskname>.
Hope this helps.

Assuming a project structure of MyApplication (root) with app (android) and backend (appengine)
If you want to build only the backend. You should run the assemble task on that gradle module. Unfortunately running the task directly from the "Gradle" tab doesn't seem to run the task against the module alone, it runs it on everything. So you have two options.
run build from the command line : ./gradlew :backend:assemble
create a run configuration in the IDE for your gradle build, with the values
Name:Backend Build (or something),
Gradle project: MyApplication:backend (pick from dropdown),
Tasks :backend:assemble
and use that to build your backend by itself.
Both seem kind of annoying. You can also try to initiate an individual module rebuild directly when you run.
If you take a look at your backend run configuration (Run -> Edit Configurations), in the section Before launch:, you see a Make which does a project rebuild. You might need to remove that from the run configuration so it doesn't try to rebuild the whole project before deploying. To replace that with a gradle assemble of your module, click the +, and add a new Run Gradle task and configure it as above in "2".
I've filed a bug against this : https://code.google.com/p/android/issues/detail?id=168875&thanks=168875&ts=1429554595 I think the default behavior should be switched (use gradle assemble instead of make).
Generating Client libraries is done with some magic in Gradle. If you look at the build file for your Android App, it should reference a configuration on your backend called android-endpoints so the endpoint are generated as a compile dependency of your app module

Related

Convert Gradle/Kotlin project to Android Project

I created a kotlin project with the command gradle init, which I can build and run without issues. I know AndroidStudio uses gradle to build/deploy an android project. With this in mind, can i modify the generated kotlin project to also become an android project? I want that when gradle build is issued, an apk file is generated, instead of the jar being generated right now. And, if possible, being able to deploy the apk to the phone connected to the computer (either via usb or wi-fi).
You actually can, just add the AGP (Android Gradle Plugin) to your build.gradle script.
And from there, structure your project to as Android Project.
Of course it's like manual type of doing it, It's easier just to start an Android Project from Android Studio cause it will generate all the files needed for Android Project.

Android Studio Cordova project doesn't have the option to generate as APK/App Bundle

I have inherited an Android Studio project from a previous developer that uses Cordova. This is a template that we have used for three years for each new app we build. I have very little experience with building in Android and have Googled my way through so far.
With the August 2021 update on Google Play Store I'm now needing to submit our newest app in bundle format, but I don't seem to have a way to do this.
I have seen guides referring to a 'Generate apk/bundle' option that should be visible under 'build' from the top menu, but this option is not visible for me:
Whenever I've used this template before, there was a message displayed saying "Migrate Project to Gradle? This project does not use the Gradle build system". My understanding from a day of research is that although my module had a build.gradle folder, the top level project also needed one (and a settings.gradle file). This seems to have worked as there is now a 'Gradle' that syncs successfully when I make a change.
When I use the command 'cordova build', the project is building successfully.
I've also read that you can use gradlew bundlerelease to generate a bundle, but if I use gradlew tasks then there is no task available relating to bundling.
I'd really appreciate any advice on how I bundle this app please.
EDIT: By changing directory into app/platforms/android, the gradlew bundlerelease function works. I receive a BUILD SUCCESSFUL message, but nothing is actually being generated.
You should be able to generate the bundle using
cordova build android --release -- --packageType=bundle
See https://github.com/apache/cordova-android/issues/729 for more details
In case anyone is reading this in the future, thought I'd post my solution here.
My issue was that after manually adding the top project-level build.gradle and gradle.settings files, Android Studio converted it to be Gradle-based and somehow my existing module was not recognised. I had to create a new module inside the project, upgrade Cordova to 10.0.0 and migrate the project to Android X.
After the above changes, the menu option to generate the app bundle existed and finally worked.

Is running gradle via android studio different from via Terminal ?

When i ran Gradle task via Android Studio' GUI (using IDE‘s own Gradle distribution), no dependencies need to download. But after that, when i did the same via terminal the first time, it would download some dependencies, for example, "lint" . Is it normal ? I don't want to cache two duplicated dependencies.
I don't want to cache two duplicated dependencies.
Gradle (and Maven) dependencies are only contained within your user home folder, in .gradle and .m2 respectively. Unless you have modified those files otherwise, of course.
Gradle just happens to be included in Android Studio. If you are able to run Gradle independently in the terminal, then you have two installations of Gradle.
The gradle wrapper would be downloaded separately of the local system installation.
for example, "lint"
Lint shouldn't be downloading anything. It only inspects your code for errors and warnings.

In Cordova/Phonegap why we need to build the project for each platform?

I created a new cordova project (from the command line, cordova create firstProject com.examplefirstproject FirstProject), then I added the platoform that I need (cordova platform add android) and at this point I read from the Cordova documentation that I need to build the project (cordova build android).
Why we need to build the project?
I tried to emulate the project without building it and it works fine. So, I'm asking why I should run the command to build the project.
The "only difference" from a project where I run the build command is the presence of more folders in firstproject\platforms\android (here is the list of folders and files of the not builded project and here is the list of the builded project).
The build command will recompile the app. There are many situations when this is important to do. Whenever, you make a change to core functionality of the app (not the HTML, JS, CSS etc), you will need to re-build the app for these changes to become apparent. Also, you will find when your project is finished, in order to publish the app you will have to build a release version of the app.
You don't need to build the app when you are merely editing the content of your app, which is what is causing your confusion it would seem.
It's also worth noting that when you use the 'run' command to emulate the app, this will also create a fresh build of the app.

Android autobuild + tests

what is the easiest way to run an autobuild of android app, that includes compiling, running tests and creating an apk file (using ANT)?
thanks!
Use the android tool from the SDK. If you already have something that's a running project in Eclipse you just need to run the android project in the base directory of your project:
android update project --path .
And it should generate the ant build scripts needed to be able to build debug and release apks from the command line.
As for testing, there's also options to create a new test project using the android tool: http://developer.android.com/guide/developing/testing/testing_otheride.html The docs in there go through details for automating and setting up test projects.
If you're looking for a way to automate all the stuff check out one of the continuous integration servers, like Jenkins (http://jenkins-ci.org/) They're tailored to watch a software repository, automate some actions, and monitor the output.

Categories

Resources