0

I create a HelloWorld application following Android's official link. It runs fine in the Android Studio Emulator. I take the same application folder and add it in the packages/app/ folder of Android source code. Then I add the name of the app in build/target/product/core.mk file. Then I add an Android.mk in the app folder which looks like the following:

ROOT_LOCAL_PATH := $(call my-dir)
$(info Start building SohamFirstApp from path $(ROOT_LOCAL_PATH) ...)

include $(call all-subdir-makefiles)
include $(ROOT_LOCAL_PATH)/app/src/main/Android.mk

The app/src/main/Android.mk looks like:

MAIN_LOCAL_PATH := $(call my-dir)
# Call to build JNI libs
include $(call all-subdir-makefiles)
LOCAL_PATH := $(MAIN_LOCAL_PATH)

$(info Entering $(LOCAL_PATH) ...)

include $(CLEAR_VARS)

LOCAL_PACKAGE_NAME := SohamFirstApp

LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_CERTIFICATE := platform
LOCAL_PROGUARD_ENABLED := disabled

LOCAL_REQUIRED_MODULES := libnative-lib

LOCAL_STATIC_ANDROID_LIBRARIES := \
    android-support-v4 \
    android-support-v7-recyclerview \
    android-support-v7-preference \
    android-support-v7-appcompat \
    android-support-v14-preference \
    android-support-v17-preference-leanback \
    android-support-v17-leanback \
    android-support-v4 \

LOCAL_SRC_FILES := \
    $(call all-java-files-under, java)

LOCAL_RESOURCE_DIR := \
    $(LOCAL_PATH)/res 

LOCAL_USE_AAPT2 := true
LOCAL_AAPT_FLAGS := \
    --auto-add-overlay 

include $(BUILD_PACKAGE)

But when I compile Android, I get the following error:

packages/apps/SohamFirstApp/app/src/main/res/layout/activity_main.xml:9: error: attribute 'com.example.sohamfirstapp:layout_constraintBottom_toBottomOf' not found.
packages/apps/SohamFirstApp/app/src/main/res/layout/activity_main.xml:9: error: attribute 'com.example.sohamfirstapp:layout_constraintLeft_toLeftOf' not found.
packages/apps/SohamFirstApp/app/src/main/res/layout/activity_main.xml:9: error: attribute 'com.example.sohamfirstapp:layout_constraintRight_toRightOf' not found.
packages/apps/SohamFirstApp/app/src/main/res/layout/activity_main.xml:9: error: attribute 'com.example.sohamfirstapp:layout_constraintTop_toTopOf' not found.

I have checked my Android Studio Emulator Android version and the Android source code Android version to be both Android 8.1 What is the reason of this error? and how can I remove it?

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
sal_guy
  • 199
  • 2
  • 14

2 Answers2

0

Think that the Android.mk might be missing com.android.support.constraint and that packages/apps/SohamFirstApp/app/src/main/res/layout/activity_main.xml should be:

android:layout_constraintBottom_toBottomOf=""
android:layout_constraintLeft_toLeftOf=""
android:layout_constraintRight_toRightOf=""
android:layout_constraintTop_toTopOf=""
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Where should I add that in `Android.mk`? `app/build.gradle` already has `implementation 'com.android.support.constraint:constraint-layout:1.1.3'` in the dependencies. I did what you said to do in `activity.xml`, but got the same error. – sal_guy Oct 24 '19 at 22:32
  • @SohamSinha the name-space should become known when added below `LOCAL_STATIC_ANDROID_LIBRARIES`; the Gradle dependencies do not really matter primarily, because it will not fetch them, so they need to be provided. The error message might be a subsequent error of not having provided the library. – Martin Zeitler Oct 24 '19 at 22:35
  • Oh I see what you are saying. Do you know what line exactly I should add in Android.mk? – sal_guy Oct 24 '19 at 22:37
  • `android-support-constraint` needs to be provided as `LOCAL_STATIC_ANDROID_LIBRARIES`. – Martin Zeitler Oct 24 '19 at 22:49
  • It now says: error: SohamFirstApp (APPS android-x86) missing android-support-constraint (JAVA_LIBRARIES android-x86) – sal_guy Oct 24 '19 at 22:52
0

constraint-layout and constraint-layout-solver needed to be added in the app in AOSP. I added that. The process is described here: https://stackoverflow.com/a/58738288/9605189

sal_guy
  • 199
  • 2
  • 14