Search code examples
androidandroid-source

How to add Android Studio created applications in android source code?


I have created an application in Android Studio. Now I want to add that project in android_source_code/packages/apps/ folder and build the entire AOSP image so that my app will be a system app.

Now the problem is the application is having a folder structure of Android Studio which is entirely different from Eclipse and android_source_code expects it to be in Eclipse folder structure format. So how can I achieve that?

Will android_source_code accepts the Studio folder structure or Do I need to write a script to transform the Studio folder structure to Eclipse format while copying to the android_source_code?

Any help will be appreciated.

Thanks


Solution

  • Integrating an Android Studio project into the AOSP build is not a trivial task. As far as I know, there aren't any dedicated tools to convert an Android Studio project (that is using the Gradle build system) to AOSP project (that is using the make build system).

    One of the approaches you might want to investigate is creating your own Gradle task that will build the Android.mk file based on the source structure of you Android Studio project (i.e. finding all the relevant source sets for your JAVA files, resources, manifests, AIDLs etc ... and creating an Android.mk file that will tell the AOSP build system exactly wher to find each and every file). This approach might work for relatively simple projects, but as soon as you start using more complex features (i.e. Modules, Manifest/Resources merging and so on), you will find it extremely difficult to generate the Android.mk without the help of the Gradle build system.

    I would consider a different approach:

    As a pre-installed privileged application, you can get the same privileges as a system application and perform whatever tasks you might wish to perform with no restrictions.

    To do so, you can build your application using Android Studio, and define the already built APK as a BUILD_PREBUILT component that will be placed in the priv-app folder of the device.

    Here is an exsample of the Android.mk file that will take your pre built APK and install it on the device as a pre installed application:

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := your_app_name
    LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
    LOCAL_MODULE_CLASS := APPS
    LOCAL_MODULE_SUFFIX := .apk
    LOCAL_PRIVILEGED_MODULE := true
    LOCAL_CERTIFICATE := platform
    include $(BUILD_PREBUILT)
    

    In addition, depending on what your application needs to do, you might want to declare in your manifest that your application is a system app:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    ...
    android:sharedUserId="android.uid.system">