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

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐