Converting android ndk build files to gradle - android-ndk

Is there any documentation on converting a application.mk/android.mk file to a gradle based build.gradle file?

good links, QArea. Thanks a lot!
At this moment NDK support in Gradle are very limited. If you need to assemble something that gradle not provides that function
I do like this.
I collect the old-fashioned, but to .so-patches automatically picks up the Gradle-plugin:
ndk-build -j4 NDK_LIBS_OUT=src/main/jniLibs
Otherwise, you must wait for next version of gradle 0.13. Devs promise that NDK will fix integration with NDK.

I made a script tool to convert android.mk building system to gradle building system, because I wanted to test the demo source codes in:
https://android.googlesource.com/platform/development/+/05523fb0b48280a5364908b00768ec71edb847a2/samples
But after searching whole internet, I found no one did it yet. So I created this tool by myself. But even with this tool, we couldn't ensure all projects in AndroidSamples could be built and executed successfully because of the API versions and features mismatch. So I created my own projects for https://android.googlesource.com/platform/development/+/05523fb0b48280a5364908b00768ec71edb847a2/samples
And I want to convert those demo projects one by one.
Now the whole source codes are here:
https://github.com/clockzhong/AndroidSamples
I already successfully converted some samples into gradle building system and executed them correctly on my android phones. But I still have some version mismatch issues, anyway, I'll mentioned it in the project check-in comments.

Related

Importing LIBGDX library gdx-backend-android.jar into Android Studio Project

After a hiatus of a couple of years I'm picking up Android development again.
I installed the newest Android Studio(4.1.1) with the latest Android SDK version (Android 11, API 30). After that I created a new project with gdx-setup.
If I add the old java source to my newly generated project I get this error:
error: package com.badlogic.gdx.backends.android does not exist
I'm not sure how to add this jar into the new project. In the Gradle configuration I see mentions of the backend, but it's not available.
I also downloaded the 'gdx-backend-android.jar' from the nightly build and put the jar in the Android library folder, all to no avail.
Does anyone actually know how to correctly add this dependency into my project?
I added the jar but still have an error, don't mind the other errors, I first need to fix the GDX import.
The project dependencies are managed by Gradle, so there is no need for you to directly touch any .jar files at all.
The most likely issue you're facing is that you are trying to use Android-specific classes from the core module, which is platform agnostic.
In a typical libGDX project, you do almost all your game code in the core module so it can easily be compiled for any platform. The code you showed above would be in the android module, but your LiveWallpaperStarter class would be part of core.
Some might say there's no reason to use core at all if you're making a Live Wallpaper, since it can't run on any other platforms besides Android. But there is some advantage in keeping the rendering in core so you can test in a desktop game window, because you can more rapidly compile and run on the desktop. This library has some tools that make it easy to wrap your rendering code in a class that lets you simulate a live wallpaper on desktop, for testing.

What does the Android Studio delegateBuildRunToGradle do?

I'm trying to resolve some dependency issues when using an externally installed Gradle, rather than the one that come with Android Studio (AS). I then came across the particular AS setting under
File > Settings > Build,Execution,Deployment > Build Tools > Gradle > Runner.
[x] Delegate IDE build/run actions to Gradle
This is apparently also available as the Gradle config delegateBuildRunToGradle. But I can't find any sane explanation as to what it does. I thought all AS builds used Gradle...
While the Gradle doc page say it's on by default. This was not the case for my AS 3.2.2.
What does this option do?
(When should it be used?)
I was hoping to have a more precise answer, but since nothing has come forward here, I guess the only answer is that (what is written in the screenshot above) the IntelliJ IDEA has it's own way to make the builds. For many practical purposes it is probably better to have a more updated and working Gradle installation and enable the above option, to let it do its job.

Android Studio: Where are Gradle build tasks defined?

I am trying to learn about how a gradle build works. When I do a build, I see a bunch of tasks executed, e.g.:
app:assembleDebug
app:preBuild
app:packageDebug
I would like to see exactly what these tasks are doing. I assume these are Gradle / Groovy scripts. I tried unzipping all the jars under Android Studio. Lots of stuff there, but I don't see anything relevant (I may have missed something in the voluminous listing). Are these tasks hidden within a class file? Am I looking in the wrong place?
All these tasks are created by the Gradle Android plugin, either the library version (com.android.library) or the application version (com.android.application). You can find the source code of these plugins in this repository.
However, it may be difficult to get insight on each task as some of them may be implemented by custom task types of the Android plugin, others may only be regular configured Gradle tasks. Also, the configuration of the tasks may be spreaded across multiple files, as many of them may be created dynamically.
But, in my opinion, it is unnecessary to know the exact functionality of each task, instead you should focus on the basic concepts of Android development and the Gradle plugin, e.g. build types and variants. The Android plugin provides a specific DSL and depending on the specified configuration, it will create the tasks automatically.

Can I generate an unsigned APK using dexguard?

My question is quite simple but it seems I cannot find the answer on the web and since dexGuard does not have a trial period I cannot test it myself.
Can I generate an unsigend apk obfuscated/encrypted with dexguard in Android Studio. I've been told that is not possible because the signature is used during the obfuscation/encryption process but I feel like I'm missing something.
I would like to know if I can obtain the same result I obtain with "assemble release" gradle task with proguard enabled but using dexguard instead for a better protection.
Thank you for your help
Dexguard is a better version than Proguard so it has all the functionalities that has its little brother. From the Dexguard docs:
The procedure for building Android applications and libraries remains
the same. You can invoke gradle with the usual targets, such as
assemble, build, install, and connectedInstrumentTest. For instance,
to build the release version of your application and install it on a
connected device:
gradle installRelease
To build the release version of a library:
gradle assembleRelease
Debug builds use debug settings, without
optimization or obfuscation. Release builds use release settings, with
full optimization and obfuscation. Applications can optionally be
signed. The entries in application archives are always zip-aligned for
efficiency.
Additionally you can use the Standalone version which makes DexGuard run from the command line. By using this you can post-process an existing Android application (.apk file).
I only use Dexguard to obfuscate a Library in Standalone mode but I am pretty sure it will work.

How do I incorporate robolectric into an existing Android Studio project?

The android ecosystem, particularly Android Studio, has been changing a lot over the last year or so. I've found many sets of instructions for incorporating robolectric into a project, written at many points during that period. And I haven't yet made one work on my project.
Which commands do I need to add to my app build.gradle?
Which commands do I need to add to my project build.gradle?
Do I need to use Junit 4 in order to use robolectric?
Are there other libraries needed? What versions?
Do my tests need to be in src/test rather than src/androidTest?
What other information do I need?
I'm using:
Android Studio 1.1.0
gradle 1.1.0
junit 4.12
hamcrest-library 1.3
mockito-core 1.10.19
dexmaker 1.0
dexmaker-mockito 1.0
I suppose that you expect to run tests from Android Studio in addition to be able run them from command line only.
I think the most up to date example of usage Robolectric with latest android gradle plugin is this.
One note: I see dependencies to dexmaker and dexmaker-mockito that gives me assumption that you use Instrumental tests instead of plain junit tests.
It is quite dumb answer with just reference but I can not be more specific until you have specific issue

Resources