Manually porting Android Studio Project into AOSP: what is wrong with my Android.mk? (Nougat)

127 views
Skip to first unread message

Vincenzo Pappano

unread,
Mar 30, 2020, 10:54:47 AM3/30/20
to android-porting

I am experimenting with this example.

https://www.truiton.com/2014/11/bound-service-example-android/

It only has two java classes

1. BoundService.java ("class BoundService extends service") that instantiates a chronometer and returns the time elapsed since the service was started

2. MainActivity.java, which starts the service and binds to it.

The code compiles on a Windows PC, using Android Studio. I can install and run the apk file on my dedicated embedded android target. The app runs fine.

I would like to be able to compile the example the code on a Linux server running Ubuntu. The server has been setup to run AOSP. Specifically I would like to build the app from source code in the /packages/apps/ folder using a dedicated Android.mk file

The cleaned-up directory structure is given below

\---src
|   Android.mk
|   AndroidManifest.xml
|
+---java
|   \---com
|       \---example
|           \---chrono
|                   BoundService.java
|                   MainActivity.java
|
\---res
    +---drawable
    +---drawable-v24
    +---layout
    +---mipmap-anydpi-v26
    +---mipmap-hdpi
    +---mipmap-mdpi
    +---mipmap-xhdpi
    +---mipmap-xxhdpi
    +---mipmap-xxxhdpi
    \---values

The code is successfully compiled into a .APK file ("mm -B -j4"). I can install the APK file (adb install my_app.apk). However, when I run the app, the app crashes "My_App has stopped"

The Android.mk file is given below

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_STATIC_JAVA_LIBRARIES := android-common
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout

LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/
v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res

LOCAL_PACKAGE_NAME := BoundService
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_MODULE_TAGS := tests

LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout:android.common:android.support.v4

include $(BUILD_PACKAGE)



The android manifest file is given below



<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.chrono"
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:versionCode="1"
          android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="25"
        android:targetSdkVersion="25" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <service android:name=".BoundService">
        </service>
    </application>

</manifest>



The app runs if compiled through Android Studio on my Windows PC, but it doesn't if I compile on the Ubuntu machine using AOSP and the command line. I am missing something in the "translation". Where is my problem? Android.mk? AndroidManifest.xml? Somewhere else?

Thanks !!!
BoundService.zip

Vincenzo Pappano

unread,
Mar 30, 2020, 11:57:22 AM3/30/20
to android-porting
All,

My apologies ... I initially thought the cause of the crash was the communication between the MainActivity and the BoundServer.

As it turns out, the reason of the crash is AppCompatActivity. When I changed it to Activity, the app ran without a problem.

I am now working on getting the example to work with AppCompatActivity ... If anybody has any suggestion, that would be greatly appreciated   :-)

Vincenzo Pappano

unread,
Mar 30, 2020, 3:49:16 PM3/30/20
to android-porting

All,

I managed to get the app to compile and run.

I did a search for "AppCompatActivity" in the /packages/apps folder for my AOSP installation.

It returned a few hits in the java files for the Dialer app. I looked at the Android.mk file in Dialer app directory and used it as a reference (with minimal modifications) for my custom Android.mk



On Monday, March 30, 2020 at 10:54:47 AM UTC-4, Vincenzo Pappano wrote:
Reply all
Reply to author
Forward
0 new messages