Migrate android.car Droiddoc to Soong

Test: Build:
m -j android.car-stubs
m -j android.car-stub-docs
m -j android.support.car-docs
APICheck:
m -j android.car-stubs-docs-check-current-api
m -j android.car-stubs-docs-check-last-released-api
m -j android.car-system-stubs-docs-check-current-api
m -j android.car-system-stubs-docs-check-last-released-api
m -j android.support.car-stubs-docs-check-current-api

Also diff the generated proguard api file between old one and new one.

Bug: b/70351683
Change-Id: I29dd1a53b3b7feee0f708c64005df9ade82a2ed6
Merged-In: I29dd1a53b3b7feee0f708c64005df9ade82a2ed6
(cherry-picked from commit: 6e86569abac63f3567c3a2e2ae80b1341b8421ec)
diff --git a/Android.mk b/Android.mk
index 04f8004..8b1efbf 100644
--- a/Android.mk
+++ b/Android.mk
@@ -12,21 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-#
-
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
-CAR_API_CHECK := $(LOCAL_PATH)/apicheck.mk
-api_check_current_msg_file := $(LOCAL_PATH)/apicheck_msg_current.txt
-api_check_last_msg_file := $(LOCAL_PATH)/apicheck_msg_last.txt
-
-.PHONY: update-car-api
-
 # Include the sub-makefiles
 include $(call all-makefiles-under,$(LOCAL_PATH))
-
-# Clear out variables
-CAR_API_CHECK :=
-api_check_current_msg_file :=
-api_check_last_msg_file :=
diff --git a/apicheck.mk b/apicheck.mk
deleted file mode 100644
index b87c7d2..0000000
--- a/apicheck.mk
+++ /dev/null
@@ -1,286 +0,0 @@
-# Copyright (C) 2016 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.
-
-#
-# Input variables
-#
-# $(car_module) - name of the car library module
-# $(car_module_api_dir) - dir to store API files
-# $(car_module_include_systemapi) - if systemApi file should be generated
-# $(car_module_proguard_file) - where to output the proguard file, if empty no file will be produced
-# $(car_module_java_libraries) - dependent libraries
-# $(car_module_java_packages) - list of package names containing public classes
-# $(car_module_src_files) - list of source files
-# $(api_check_current_msg_file) - file containing error message for current API check
-# $(api_check_last_msg_file) - file containing error message for last SDK API check
-# ---------------------------------------------
-
-ifeq ($(BOARD_IS_AUTOMOTIVE), true)
-ifneq ($(TARGET_BUILD_PDK), true)
-#
-# Generate the public stub source files
-# ---------------------------------------------
-include $(CLEAR_VARS)
-
-car_module_api_file := \
-    $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(car_module)_api.txt
-car_module_removed_file := \
-    $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(car_module)_removed.txt
-
-LOCAL_MODULE := $(car_module)-stubs
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := $(car_module_src_files)
-LOCAL_JAVA_LIBRARIES := $(car_module_java_libraries) $(car_module)
-LOCAL_ADDITIONAL_JAVA_DIR := \
-    $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(car_module),,COMMON)/src
-LOCAL_SDK_VERSION := $(CAR_CURRENT_SDK_VERSION)
-
-LOCAL_DROIDDOC_STUB_OUT_DIR := $(TARGET_OUT_COMMON_INTERMEDIATES)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates/src
-
-LOCAL_DROIDDOC_OPTIONS:= \
-    -stubpackages "$(subst $(space),:,$(car_module_java_packages))" \
-    -api $(car_module_api_file) \
-    -removedApi $(car_module_removed_file) \
-    -nodocs \
-    -hide 113 \
-    -hide 110
-LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR := external/doclava/res/assets/templates-sdk
-LOCAL_UNINSTALLABLE_MODULE := true
-
-include $(BUILD_DROIDDOC)
-car_stub_stamp := $(full_target)
-$(car_module_api_file) : $(full_target)
-
-ifeq ($(car_module_include_systemapi), true)
-#
-# Generate the system stub source files
-# ---------------------------------------------
-include $(CLEAR_VARS)
-
-car_module_system_api_file := \
-    $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(car_module)_system_api.txt
-car_module_system_removed_file := \
-    $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(car_module)_system_removed.txt
-
-LOCAL_MODULE := $(car_module)-system-stubs
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := $(car_module_src_files)
-LOCAL_JAVA_LIBRARIES := $(car_module_java_libraries) $(car_module)
-LOCAL_ADDITIONAL_JAVA_DIR := \
-    $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(car_module),,COMMON)/src
-LOCAL_SDK_VERSION := $(CAR_CURRENT_SDK_VERSION)
-
-LOCAL_DROIDDOC_STUB_OUT_DIR := $(TARGET_OUT_COMMON_INTERMEDIATES)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates/src
-
-LOCAL_DROIDDOC_OPTIONS:= \
-    -stubpackages "$(subst $(space),:,$(car_module_java_packages))" \
-    -showAnnotation android.annotation.SystemApi \
-    -api $(car_module_system_api_file) \
-    -removedApi $(car_module_system_removed_file) \
-    -nodocs \
-    -hide 113 \
-    -hide 110
-LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR := external/doclava/res/assets/templates-sdk
-LOCAL_UNINSTALLABLE_MODULE := true
-
-include $(BUILD_DROIDDOC)
-car_system_stub_stamp := $(full_target)
-$(car_module_system_api_file) : $(full_target)
-
-#($(car_module_include_systemapi), true)
-endif
-
-
-ifneq ($(strip $(car_module_proguard_file)),)
-#
-# Generate a proguard files
-# ---------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := $(car_module)-proguard
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := $(car_module_src_files)
-LOCAL_JAVA_LIBRARIES := $(car_module_java_libraries) $(car_module)
-LOCAL_ADDITIONAL_JAVA_DIR := \
-    $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(car_module),,COMMON)/src
-LOCAL_SDK_VERSION := $(CAR_CURRENT_SDK_VERSION)
-
-docs_proguard_intermediates_output := $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),,COMMON)/keep_list.proguard
-LOCAL_DROIDDOC_OPTIONS := -proguard $(docs_proguard_intermediates_output)
-
-include $(BUILD_DROIDDOC)
-
-update-car-api: PRIVATE_PROGUARD_INTERMEDIATES_OUTPUT := $(docs_proguard_intermediates_output)
-update-car-api: PRIVATE_PROGUARD_OUTPUT_FILE := $(car_module_proguard_file)
-update-car-api: PRIVATE_CAR_MODULE := $(car_module)
-update-car-api: $(car_module)-proguard-docs | $(ACP)
-	@echo $(PRIVATE_CAR_MODULE) copying $(PRIVATE_PROGUARD_INTERMEDIATES_OUTPUT) to $(PRIVATE_PROGUARD_OUTPUT_FILE)
-	$(hide) $(ACP) $(PRIVATE_PROGUARD_INTERMEDIATES_OUTPUT) $(PRIVATE_PROGUARD_OUTPUT_FILE)
-
-# cleanup vars
-docs_proguard_output :=
-# ($(strip $(car_module_proguard_file)),)
-endif
-
-
-#
-# Check public API
-# ---------------------------------------------
-.PHONY: $(car_module)-check-public-api
-checkapi: $(car_module)-check-public-api
-$(car_module): $(car_module)-check-public-api
-
-last_released_sdk_$(car_module) := $(lastword $(call numerically_sort, \
-    $(filter-out current, \
-        $(patsubst $(car_module_api_dir)/%.txt,%, $(wildcard $(car_module_api_dir)/*.txt)) \
-    )))
-
-# Check that the API we're building hasn't broken the last-released SDK version
-# if it exists
-ifneq ($(last_released_sdk_$(car_module)),)
-$(eval $(call check-api, \
-    $(car_module)-checkapi-last, \
-    $(car_module_api_dir)/$(last_released_sdk_$(car_module)).txt, \
-    $(car_module_api_file), \
-    $(car_module_api_dir)/removed.txt, \
-    $(car_module_removed_file), \
-    -hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 -hide 26 -hide 27 \
-        -warning 7 -warning 8 -warning 9 -warning 10 -warning 11 -warning 12 \
-        -warning 13 -warning 14 -warning 15 -warning 16 -warning 17 -warning 18 -hide 113, \
-    cat $(api_check_last_msg_file), \
-    $(car_module)-check-public-api, \
-    $(car_stub_stamp)))
-endif
-
-# Check that the API we're building hasn't changed from the not-yet-released
-# SDK version.
-$(eval $(call check-api, \
-    $(car_module)-checkapi-current, \
-    $(car_module_api_dir)/current.txt, \
-    $(car_module_api_file), \
-    $(car_module_api_dir)/removed.txt, \
-    $(car_module_removed_file), \
-    -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 \
-        -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 \
-        -error 21 -error 23 -error 24 -error 25 -hide 113, \
-    cat $(api_check_current_msg_file), \
-    $(car_module)-check-public-api, \
-    $(car_stub_stamp)))
-
-.PHONY: update-$(car_module)-api
-update-$(car_module)-api: PRIVATE_API_DIR := $(car_module_api_dir)
-update-$(car_module)-api: PRIVATE_MODULE := $(car_module)
-update-$(car_module)-api: PRIVATE_REMOVED_API_FILE := $(car_module_removed_file)
-update-$(car_module)-api: PRIVATE_PROGUARD_FILE := $(car_module_proguard_file)
-update-$(car_module)-api: $(car_module_api_file) | $(ACP)
-	@echo Copying $(PRIVATE_MODULE) current.txt
-	$(hide) $(ACP) $< $(PRIVATE_API_DIR)/current.txt
-	@echo Copying $(PRIVATE_MODULE) removed.txt
-	$(hide) $(ACP) $(PRIVATE_REMOVED_API_FILE) $(PRIVATE_API_DIR)/removed.txt
-
-# Run this update API task on the update-car-api task
-update-car-api: update-$(car_module)-api
-
-ifeq ($(car_module_include_systemapi), true)
-
-#
-# Check system API
-# ---------------------------------------------
-.PHONY: $(car_module)-check-system-api
-checkapi: $(car_module)-check-system-api
-$(car_module): $(car_module)-check-system-api
-
-last_released_system_sdk_$(car_module) := $(lastword $(call numerically_sort, \
-    $(filter-out system-current, \
-        $(patsubst $(car_module_api_dir)/%.txt,%, $(wildcard $(car_module_api_dir)/system-*.txt)) \
-    )))
-
-# Check that the API we're building hasn't broken the last-released SDK version
-# if it exists
-ifneq ($(last_released_system_sdk_$(car_module)),)
-$(eval $(call check-api, \
-    $(car_module)-checksystemapi-last, \
-    $(car_module_api_dir)/$(last_released_system_sdk_$(car_module)).txt, \
-    $(car_module_system_api_file), \
-    $(car_module_api_dir)/system-removed.txt, \
-    $(car_module_system_removed_file), \
-    -hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 -hide 26 -hide 27 \
-        -warning 7 -warning 8 -warning 9 -warning 10 -warning 11 -warning 12 \
-        -warning 13 -warning 14 -warning 15 -warning 16 -warning 17 -warning 18 -hide 113, \
-    cat $(api_check_last_msg_file), \
-    $(car_module)-check-system-api, \
-    $(car_system_stub_stamp)))
-endif
-
-# Check that the API we're building hasn't changed from the not-yet-released
-# SDK version.
-$(eval $(call check-api, \
-    $(car_module)-checksystemapi-current, \
-    $(car_module_api_dir)/system-current.txt, \
-    $(car_module_system_api_file), \
-    $(car_module_api_dir)/system-removed.txt, \
-    $(car_module_system_removed_file), \
-    -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 \
-        -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 \
-        -error 21 -error 23 -error 24 -error 25 -hide 113, \
-    cat $(api_check_current_msg_file), \
-    $(car_module)-check-system-api, \
-    $(car_stub_stamp)))
-
-.PHONY: update-$(car_module)-system-api
-update-$(car_module)-system-api: PRIVATE_API_DIR := $(car_module_api_dir)
-update-$(car_module)-system-api: PRIVATE_MODULE := $(car_module)
-update-$(car_module)-system-api: PRIVATE_REMOVED_API_FILE := $(car_module_system_removed_file)
-update-$(car_module)-system-api: PRIVATE_PROGUARD_FILE := $(car_module_proguard_file)
-update-$(car_module)-system-api: $(car_module_system_api_file) | $(ACP)
-	@echo Copying $(PRIVATE_MODULE) system-current.txt
-	$(hide) $(ACP) $< $(PRIVATE_API_DIR)/system-current.txt
-	@echo Copying $(PRIVATE_MODULE) system-removed.txt
-	$(hide) $(ACP) $(PRIVATE_REMOVED_API_FILE) $(PRIVATE_API_DIR)/system-removed.txt
-
-# Run this update API task on the update-car-api task
-update-car-api: update-$(car_module)-system-api
-
-
-
-#($(car_module_include_systemapi), true)
-endif
-
-#($(TARGET_BUILD_PDK),true)
-endif
-
-#($(BOARD_IS_AUTOMOTIVE), true)
-endif
-#
-# Clear variables
-# ---------------------------------------------
-car_module :=
-car_module_api_dir :=
-car_module_src_files :=
-car_module_java_libraries :=
-car_module_java_packages :=
-car_module_api_file :=
-car_module_removed_file :=
-car_module_system_api_file :=
-car_module_system_removed__file :=
-car_stub_stamp :=
-car_system_stub_stamp :=
-car_module_include_systemapi :=
-car_module_proguard_file :=
diff --git a/apicheck_msg_current.txt b/apicheck_msg_current.txt
deleted file mode 100644
index fa3598f..0000000
--- a/apicheck_msg_current.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-
-******************************
-You have tried to change a car library API from what has been previously approved.
-
-To make these errors go away, you have two choices:
-   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
-      errors above.
-
-   2) You can update current.txt by executing the following command:
-         make update-car-api
-
-      To submit the revised current.txt to the main Android repository,
-      you will need approval.
-******************************
diff --git a/apicheck_msg_last.txt b/apicheck_msg_last.txt
deleted file mode 100644
index 5f54821..0000000
--- a/apicheck_msg_last.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-
-******************************
-You have tried to change a car library API from what has
-been previously released in an SDK. Please fix the errors listed above.
-******************************
diff --git a/car-lib/Android.bp b/car-lib/Android.bp
index 806121f..6fe7f8b 100644
--- a/car-lib/Android.bp
+++ b/car-lib/Android.bp
@@ -70,3 +70,130 @@
     },
     installable: true,
 }
+
+doc_defaults {
+    name: "android.car-docs-default",
+    srcs: [
+        "src/**/*.java",
+        "src_feature_future/**/*.java",
+    ],
+    libs: [
+        "android.car",
+    ],
+    custom_template: "droiddoc-templates-sdk",
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+    },
+}
+
+genrule {
+    name: "android-car-last-released-api",
+    srcs: [
+        "api/released/*.txt",
+    ],
+    cmd: "cp -f $$(echo $(in) | tr \" \" \"\\n\" | sort -n | tail -1) $(genDir)/last-released-api.txt",
+    out: [
+        "last-released-api.txt",
+    ],
+}
+
+genrule {
+    name: "android-car-last-released-system-api",
+    srcs: [
+        "api/system-released/*.txt",
+    ],
+    cmd: "cp -f $$(echo $(in) | tr \" \" \"\\n\" | sort -n | tail -1) $(genDir)/last-released-system-api.txt",
+    out: [
+        "last-released-system-api.txt",
+    ],
+}
+
+droiddoc {
+    name: "android.car-stubs-docs",
+    defaults: ["android.car-docs-default"],
+    api_tag_name: "ANDROID_CAR",
+    api_filename: "api.txt",
+    removed_api_filename: "removed.txt",
+    args: "-hide 113 -hide 110 -nodocs -stubpackages android.car* ",
+    installable: false,
+    check_api: {
+        last_released: {
+            api_file: ":android-car-last-released-api",
+            removed_api_file: "api/removed.txt",
+            args: " -hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 -hide 26 -hide 27 " +
+                  " -warning 7 -warning 8 -warning 9 -warning 10 -warning 11 -warning 12 " +
+                  " -warning 13 -warning 14 -warning 15 -warning 16 -warning 17 -warning 18 -hide 113 ",
+        },
+        current: {
+            api_file: "api/current.txt",
+            removed_api_file: "api/removed.txt",
+            args: " -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 " +
+                  " -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 " +
+                  " -error 21 -error 23 -error 24 -error 25 -hide 113 ",
+        },
+    },
+}
+
+droiddoc {
+    name: "android.car-system-stubs-docs",
+    defaults: ["android.car-docs-default"],
+    api_tag_name: "ANDROID_CAR_SYSTEM",
+    api_filename: "api.txt",
+    removed_api_filename: "removed.txt",
+    args: "-hide 113 -hide 110 -nodocs -stubpackages android.car* " +
+        "-showAnnotation android.annotation.SystemApi ",
+    installable: false,
+    check_api: {
+        last_released: {
+            api_file: ":android-car-last-released-system-api",
+            removed_api_file: "api/system-removed.txt",
+            args: " -hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 -hide 26 -hide 27 " +
+                  " -warning 7 -warning 8 -warning 9 -warning 10 -warning 11 -warning 12 " +
+                  " -warning 13 -warning 14 -warning 15 -warning 16 -warning 17 -warning 18 -hide 113 ",
+        },
+        current: {
+            api_file: "api/system-current.txt",
+            removed_api_file: "api/system-removed.txt",
+            args: " -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 " +
+                  " -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 " +
+                  " -error 21 -error 23 -error 24 -error 25 -hide 113 ",
+        },
+    },
+}
+
+droiddoc {
+    name: "android.car-stub-docs",
+    srcs: [
+        "src/**/*.java",
+    ],
+    libs: [
+        "android.car",
+    ],
+    api_tag_name: "ANDROID_CAR_STUB",
+    api_filename: "api.txt",
+    custom_template: "droiddoc-templates-sdk",
+    args: "-nodocs -stubpackages android.car* ",
+    installable: false,
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+    },
+}
+
+java_library_static {
+    name: "android.car-stubs",
+    srcs: [
+        ":android.car-stub-docs",
+    ],
+    libs: [
+        "android.car",
+    ],
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+    },
+}
diff --git a/car-lib/Android.mk b/car-lib/Android.mk
index e0fa482..41c6d86 100644
--- a/car-lib/Android.mk
+++ b/car-lib/Android.mk
@@ -21,91 +21,9 @@
 
 include $(CLEAR_VARS)
 
-car_lib_sources := $(call all-java-files-under, src)
-car_lib_sources += $(call all-java-files-under, src_feature_future)
-
-car_lib_sources += $(call all-Iaidl-files-under, src)
-
-# IoStats* are parcelable types (vs. interface types), but the build system uses an initial
-# I as a magic marker to mean "interface", and due to this ends up refusing to compile
-# these files as part of the build process.
-# A clean solution to this is actively being worked on by the build team, but is not yet
-# available, so for now we just filter the files out by hand.
-car_lib_sources := $(filter-out src/android/car/storagemonitoring/IoStats.aidl,$(car_lib_sources))
-car_lib_sources := $(filter-out src/android/car/storagemonitoring/IoStatsEntry.aidl,$(car_lib_sources))
-
 ifeq ($(BOARD_IS_AUTOMOTIVE), true)
 full_classes_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,android.car,,COMMON)/classes.jar
 $(call dist-for-goals,dist_files,$(full_classes_jar):android.car.jar)
 endif
 
-# API Check
-# ---------------------------------------------
-car_module := android.car
-car_module_src_files := $(car_lib_sources)
-car_module_api_dir := $(LOCAL_PATH)/api
-car_module_java_libraries := framework
-car_module_include_systemapi := true
-car_module_java_packages := android.car*
-include $(CAR_API_CHECK)
-
-# Build stubs jar for target android-support-car
-# ---------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_JAVA_LIBRARIES := android.car
-
-LOCAL_ADDITIONAL_JAVA_DIR := $(call intermediates-dir-for,JAVA_LIBRARIES,android.car,,COMMON)/src
-
-android_car_stub_packages := \
-    android.car*
-
-android_car_api := \
-    $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/android.car_api.txt
-
-# Note: The make target is android.car-stub-docs
-LOCAL_MODULE := android.car-stub
-LOCAL_DROIDDOC_OPTIONS := \
-    -stubs $(call intermediates-dir-for,JAVA_LIBRARIES,android.car-stubs,,COMMON)/src \
-    -stubpackages $(subst $(space),:,$(android_car_stub_packages)) \
-    -api $(android_car_api) \
-    -nodocs
-
-LOCAL_DROIDDOC_SOURCE_PATH := $(LOCAL_PATH)/java/
-LOCAL_DROIDDOC_HTML_DIR :=
-
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-
-LOCAL_UNINSTALLABLE_MODULE := true
-
-include $(BUILD_DROIDDOC)
-
-$(android_car_api): $(full_target)
-
-android.car-stubs_stamp := $(full_target)
-
-###############################################
-# Build the stubs java files into a jar. This build rule relies on the
-# stubs_stamp make variable being set from the droiddoc rule.
-
-include $(CLEAR_VARS)
-
-# CAR_API_CHECK uses the same name to generate a module, but BUILD_DROIDDOC
-# appends "-docs" to module name.
-LOCAL_MODULE := android.car-stubs
-LOCAL_SOURCE_FILES_ALL_GENERATED := true
-
-# Make sure to run droiddoc first to generate the stub source files.
-LOCAL_ADDITIONAL_DEPENDENCIES := $(android.car-stubs_stamp)
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-android.car-stubs_stamp :=
-android_car_stub_packages :=
-android_car_api :=
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
 endif #TARGET_BUILD_PDK
diff --git a/car-lib/api/1.txt b/car-lib/api/released/1.txt
similarity index 100%
rename from car-lib/api/1.txt
rename to car-lib/api/released/1.txt
diff --git a/car-lib/api/2.txt b/car-lib/api/released/2.txt
similarity index 100%
rename from car-lib/api/2.txt
rename to car-lib/api/released/2.txt
diff --git a/car-lib/api/system-1.txt b/car-lib/api/system-released/system-1.txt
similarity index 100%
rename from car-lib/api/system-1.txt
rename to car-lib/api/system-released/system-1.txt
diff --git a/car-lib/api/system-2.txt b/car-lib/api/system-released/system-2.txt
similarity index 100%
rename from car-lib/api/system-2.txt
rename to car-lib/api/system-released/system-2.txt
diff --git a/car-support-lib/Android.bp b/car-support-lib/Android.bp
new file mode 100644
index 0000000..2d4269e
--- /dev/null
+++ b/car-support-lib/Android.bp
@@ -0,0 +1,103 @@
+// 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.
+
+java_library_static {
+    name: "android.support.car",
+    srcs: [
+        "src/**/*.java",
+        "src/**/I*.aidl",
+    ],
+    aidl: {
+        include_dirs: [
+            "system/bt/binder",
+        ],
+    },
+    libs: [
+        "android.car",
+    ],
+    static_libs: [
+        "androidx.annotation_annotation",
+    ],
+    platform_apis: true,
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+    },
+    installable: true,
+}
+
+doc_defaults {
+    name: "android.support.car-docs-default",
+    srcs: [
+        "src/**/*.java",
+    ],
+    libs: [
+        "android.car",
+        "android.support.car",
+        "androidx.annotation_annotation",
+    ],
+    custom_template: "droiddoc-templates-sdk",
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+    },
+}
+
+droiddoc {
+    name: "android.support.car-stubs-docs",
+    defaults: ["android.support.car-docs-default"],
+    api_tag_name: "ANDROID_SUPPORT_CAR",
+    api_filename: "api.txt",
+    removed_api_filename: "removed.txt",
+    args: "-hide 113 -hide 110 -nodocs -stubpackages android.support.car* ",
+    installable: false,
+    check_api: {
+        current: {
+            api_file: "api/current.txt",
+            removed_api_file: "api/removed.txt",
+            args: " -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 " +
+                  " -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 " +
+                  " -error 21 -error 23 -error 24 -error 25 -hide 113 ",
+        },
+    },
+}
+
+droiddoc {
+    name: "android.support.car-proguard-docs",
+    defaults: ["android.support.car-docs-default"],
+    api_tag_name: "ANDROID_SUPPORT_CAR_PROGUARD",
+    proguard_filename: "keep_list.proguard",
+    create_stubs: false,
+}
+
+// TODO(deanh) support lib should be able to be using public APIs only
+droiddoc {
+    name: "android.support.car-docs",
+    srcs: [
+        "src/**/*.java",
+    ],
+    libs: [
+        "android.car",
+        "androidx.annotation_annotation",
+    ],
+    custom_template: "droiddoc-templates-sdk",
+    create_stubs: false,
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+    },
+}
diff --git a/car-support-lib/Android.mk b/car-support-lib/Android.mk
index 6201f21..7cfba13 100644
--- a/car-support-lib/Android.mk
+++ b/car-support-lib/Android.mk
@@ -76,59 +76,8 @@
     $(call dist-for-goals, dist_files, $(built_aar):android.support.car-1p.aar)
 endif
 
-# Build support library.
-# ---------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := android.support.car
-
-#TODO(b/72620511) support lib should be able to be using public APIs only
-#LOCAL_SDK_VERSION := current
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-Iaidl-files-under, src)
-
-LOCAL_STATIC_JAVA_LIBRARIES += androidx.annotation_annotation
-
-LOCAL_JAVA_LIBRARIES += android.car
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-# API Check
-# ---------------------------------------------
-car_module := $(LOCAL_MODULE)
-car_module_src_files := $(LOCAL_SRC_FILES)
-car_module_proguard_file := $(LOCAL_PATH)/proguard-release.flags
-car_module_api_dir := $(LOCAL_PATH)/api
-car_module_java_libraries := $(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES) framework
-car_module_java_packages := android.support.car*
-car_module_include_proguard := true
-include $(CAR_API_CHECK)
-
-
-# Generate offline docs
-#---------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-Iaidl-files-under, src)
-
-LOCAL_DROIDDOC_SOURCE_PATH := $(LOCAL_PATH)/src
-
-LOCAL_JAVA_LIBRARIES := \
-    android.car \
-    androidx.annotation_annotation
-
-LOCAL_MODULE := android.support.car
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_IS_HOST_MODULE := false
-
-LOCAL_ADDITIONAL_JAVA_DIR := $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),android.support.car,,COMMON)
-
-LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR := external/doclava/res/assets/templates-sdk
-
-include $(BUILD_DROIDDOC)
-
+update-support-car-proguard-api: $(INTERNAL_PLATFORM_ANDROID_SUPPORT_CAR_PROGUARD_PROGUARD_FILE) | $(ACP)
+	@echo $(PRIVATE_CAR_MODULE) copying $(INTERNAL_PLATFORM_ANDROID_SUPPORT_CAR_PROGUARD_PROGUARD_FILE) to $(LOCAL_PATH)/proguard-release.flags
+	$(hide) $(ACP) $(INTERNAL_PLATFORM_ANDROID_SUPPORT_CAR_PROGUARD_PROGUARD_FILE) $(LOCAL_PATH)/proguard-release.flags
 
 endif #TARGET_BUILD_PDK