0

AOSP version is 8.1.0.

I have an Android App named Settings. I Develop with Android Studio and pushed it in packages/apps/MySettings. Directory like this

MySettings
├── AndroidManifest.xml
├── Android.mk
├── build.gradle
├── libs
├── res
└── src

Android.mk like this

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := MySettings
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := false

LOCAL_STATIC_JAVA_LIBRARIES := appcompat-1.1.0
LOCAL_STATIC_JAVA_LIBRARIES += BaseRecyclerViewAdapterHelper-2.9.46
LOCAL_STATIC_JAVA_LIBRARIES += constraintlayout-1.1.3
LOCAL_STATIC_JAVA_LIBRARIES += material-1.1.0
LOCAL_STATIC_JAVA_LIBRARIES += ZTextView-v1.0.2

LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_SRC_FILES := $(call all-java-files-under, src)

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := appcompat-1.1.0:/libs/appcompat-1.1.0.aar
LOCAL_AAPT_FLAGS += \
         --auto-add-overlay \
         --extra-packages androidx.appcompat
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += BaseRecyclerViewAdapterHelper-2.9.46:/libs/BaseRecyclerViewAdapterHelper-2.9.46.aar
LOCAL_AAPT_FLAGS += \
         --auto-add-overlay \
         --extra-packages com.chad.library
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += constraintlayout-1.1.3:/libs/constraintlayout-1.1.3.aar
LOCAL_AAPT_FLAGS += \
         --auto-add-overlay \
         --extra-packages androidx.constraintlayout.widget
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += material-1.1.0:/libs/material-1.1.0.aar
LOCAL_AAPT_FLAGS += \
         --auto-add-overlay \
         --extra-packages com.google.android.material
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += ZTextView-v1.0.2:/libs/ZTextView-v1.0.2.aar
LOCAL_AAPT_FLAGS += \
         --auto-add-overlay \
         --extra-packages cc.ibooker.ztextviewlib

LOCAL_MODULE_TAGS := optional

include $(BUILD_MULTI_PREBUILT)

build.gradle like this

apply plugin: 'com.android.application'

dependencies {
//    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0'
    api 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46'
    implementation 'com.github.zrunker:ZTextView:v1.0.2'
}

android {
    compileSdkVersion 27

    defaultConfig {
        applicationId "com.example.setting"
        minSdkVersion 27
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    sourceSets {
        main.manifest.srcFile 'AndroidManifest.xml'
        main.java.srcDirs = ['src']
        main.aidl.srcDirs = ['src']
        main.res.srcDirs = ['res']
    }

}

I put the above 5 aar files in the libs directory.
When I make it, if there is an Android.mk file present, I will get the error

error: No resource identifier found for attribute 'layout_constraintStart_toStartOf' in package 'com.example.setting'

If only build.gradle exists and Android.mk does not exist, make will not report an error, but the final generated ROM will not contain this APP.

I see a lot of APP source directories in the frameworks/support/samples directory, they have build.gradle but no Android.mk. How does make find them?

1 Answer 1

0

You're mixing between different build systems. Gradle is used to build regular Android apps, and is not used by AOSP, so whether it compiles with build.gradle or not is irrelevant. Android.mk or Android.bp are the files used by AOSP for build system instructions (using either old plane make or the the new Bazel format).

That's why when you remove Android.mk AOSP does not build the app, and does not include it in the final image.

Therefore you need to focus on the explicit build error you're getting with Android.mk -

error: No resource identifier found for attribute 'layout_constraintStart_toStartOf' in package 'com.example.setting'

which means the build cannot find constraints layout (which is not part of AOSP source code). Therefore either switch to a different layout (Is it really a must?) Or include ConstraintLayour source code, or build it as a shared library.

I see that you add the layout both as a LOCAL_STATIC_JAVA_LIBRARIES and LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES, I think you need to decide which one is your strategy, not both :) It's a bit hard to follow, but I guess as you define LOCAL_STATIC_JAVA_LIBRARIES the build system may be searching for the source code, not prebuilt version and not finding it. Try removing it and see if it works. Could also be the paths you specified for the prebuilt version are wrong.

Check out this answer, and this answer about integrating ConstraintLayout into AOSP

Not the answer you're looking for? Browse other questions tagged or ask your own question.