androidmk工具轉換Android.mk

Android源碼裏邊提供了快捷直接Android.mk轉換成Android.bp的工具:androidmk。

AOSP源碼以及項目編譯出來後androidmk可執行文件位置:

lenovo@HZCS13:~/coding/aosp/build/soong$ 
lenovo@HZCS13:~/coding/aosp/build/soong$ 
lenovo@HZCS13:~/coding/aosp/build/soong$ find . -name androidmk
./androidmk
./androidmk/cmd/androidmk
lenovo@HZCS13:~/coding/aosp/build/soong$ 
lenovo@HZCS13:~/coding/aosp/build/soong$ 
lenovo@HZCS13:~/coding/aosp/build/soong$ cd ..
lenovo@HZCS13:~/coding/aosp/build$ cd ..
lenovo@HZCS13:~/coding/aosp$ cd out/soong/
lenovo@HZCS13:~/coding/aosp/out/soong$ find . -name androidmk
./host/linux-x86/bin/androidmk
./.bootstrap/androidmk
./.bootstrap/androidmk-parser/test/android/soong/androidmk
./.bootstrap/androidmk-parser/pkg/android/soong/androidmk
lenovo@HZCS13:~/coding/aosp/out/soong$ 
lenovo@HZCS13:~/coding/aosp/out/soong$ 

轉換方法:

aosp/out/soong/host/linux-x86/bin/androidmk [Android.mk PATH] > [Android.bp PATH]

舉個栗子:

轉換前,

lenove@HZCS13:~/coding/aosp/packages/apps/SecureElement$ cat Android.mk 
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

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

LOCAL_PACKAGE_NAME := SecureElement
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional

LOCAL_STATIC_JAVA_LIBRARIES := android.hardware.secure_element-V1.0-java

LOCAL_PROGUARD_ENABLED := disabled

include $(BUILD_PACKAGE)

include $(call all-makefiles-under,$(LOCAL_PATH))
lenove@HZCS13:~/coding/aosp/packages/apps/SecureElement$ 

轉換後,

lenovo@HZCS13:~/coding/aosp/packages/apps/SecureElement$ ../../../out/soong/host/linux-x86/bin/androidmk Android.mk > Android.bp
lenovo@HZCS13:~/coding/aosp/packages/apps/SecureElement$ 
lenovo@HZCS13:~/coding/aosp/packages/apps/SecureElement$ 
lenovo@HZCS13:~/coding/aosp/packages/apps/SecureElement$ 
lenovo@HZCS13:~/coding/aosp/packages/apps/SecureElement$ cat Android.bp 
android_app {
    name: "SecureElement",

    srcs: ["src/**/*.java"],

    platform_apis: true,
    certificate: "platform",

    static_libs: ["android.hardware.secure_element-V1.0-java"],

    optimize: {
        enabled: false,
    },

}
lenovo@HZCS13:~/coding/aosp/packages/apps/SecureElement$ 

來個稍微複雜一點的:

前:

lenovo@HZCS13:~/coding/aosp/packages/apps/Car/Launcher$ cat Android.mk 
# Copyright (C) 2018 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ifneq ($(TARGET_BUILD_PDK), true)

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

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

LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res

LOCAL_PACKAGE_NAME := CarLauncher

LOCAL_PRIVATE_PLATFORM_APIS := true

LOCAL_REQUIRED_MODULES := privapp_whitelist_com.android.car.carlauncher

LOCAL_CERTIFICATE := platform

LOCAL_MODULE_TAGS := optional

LOCAL_PRIVILEGED_MODULE := true

LOCAL_OVERRIDES_PACKAGES += Launcher2 Launcher3 Launcher3QuickStep

LOCAL_USE_AAPT2 := true

LOCAL_PROGUARD_ENABLED := disabled

LOCAL_DEX_PREOPT := false

LOCAL_STATIC_JAVA_LIBRARIES := \
    androidx-constraintlayout_constraintlayout-solver

LOCAL_JAVA_LIBRARIES += android.car

LOCAL_STATIC_ANDROID_LIBRARIES += \
    androidx-constraintlayout_constraintlayout \
    androidx.lifecycle_lifecycle-extensions \
    car-media-common

# Including the resources for the static android libraries allows to pick up their static overlays.
LOCAL_RESOURCE_DIR += \
    $(LOCAL_PATH)/../libs/car-apps-common/res \
    $(LOCAL_PATH)/../libs/car-media-common/res

include $(BUILD_PACKAGE)

endif
lenovo@HZCS13:~/coding/aosp/packages/apps/Car/Launcher$ 

後:

lenovo@HZCS13:~/coding/aosp/packages/apps/Car/Launcher$ ../../../../out/soong/host/linux-x86/bin/androidmk Android.mk 
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

android_app {
    name: "CarLauncher",

    srcs: ["src/**/*.java"],

    resource_dirs: ["res"] + [ // Including the resources for the static android libraries allows to pick up their static overlays.
        "../libs/car-apps-common/res",
        "../libs/car-media-common/res",
    ],

    platform_apis: true,

    required: ["privapp_whitelist_com.android.car.carlauncher"],

    certificate: "platform",

    privileged: true,

    overrides: [
        "Launcher2",
        "Launcher3",
        "Launcher3QuickStep",
    ],

    optimize: {
        enabled: false,
    },

    dex_preopt: {
        enabled: false,
    },

    static_libs: [
        "androidx-constraintlayout_constraintlayout-solver",
        "androidx-constraintlayout_constraintlayout",
        "androidx.lifecycle_lifecycle-extensions",
        "car-media-common",
    ],

    libs: ["android.car"],

    product_variables: {
        pdk: {
            enabled: false,
        },
    },
}
lenovo@HZCS13:~/coding/aosp/packages/apps/Car/Launcher$ 

從以長例子可以找到一些Android.mk和Android.bp宏聲明的對應關係。

例如:

//Andorid.bp
    optimize: {
        enabled: false,
    },

    dex_preopt: {
        enabled: false,
    },


#Android.mk

LOCAL_PROGUARD_ENABLED := disabled

LOCAL_DEX_PREOPT := false

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章