Revert "Remove custom installation rules"

This reverts commit 73dceb4a5606cd0a80ef1b5b5c243ed6fdc05b05.

Bug: 141877526
Bug: 143063995
Change-Id: Ic88e86a21027bad95468e7067bc945d6ad6c483b
diff --git a/Android.bp b/Android.bp
index 3e83e65..1d55ff1 100644
--- a/Android.bp
+++ b/Android.bp
@@ -74,7 +74,7 @@
 }
 
 // Main Target to build tradefed jar
-tradefed_java_library_host {
+java_library_host {
     name: "tradefed",
     defaults: ["tradefed_defaults"],
     java_resource_dirs: [
@@ -85,7 +85,6 @@
         "tradefed-test-framework",
     ],
     manifest: "MANIFEST.mf",
-    required: ["loganalysis"],
 }
 
 java_library_host {
diff --git a/Android.mk b/Android.mk
index 07f6fff..25647f5 100644
--- a/Android.mk
+++ b/Android.mk
@@ -16,6 +16,18 @@
 COMPATIBILITY.tradefed_tests_dir := \
   $(COMPATIBILITY.tradefed_tests_dir) $(LOCAL_PATH)/res/config $(LOCAL_PATH)/tests/res/config
 
+include $(CLEAR_VARS)
+
+# makefile rules to copy jars to HOST_OUT/tradefed
+# so tradefed.sh can automatically add to classpath
+deps := $(call copy-many-files,\
+  $(call intermediates-dir-for,JAVA_LIBRARIES,tradefed,HOST)/javalib.jar:$(HOST_OUT)/tradefed/tradefed.jar)
+
+# this dependency ensures the above rule will be executed if jar is installed
+$(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar : $(deps)
+# The copy rule for loganalysis is in tools/loganalysis/Android.mk
+$(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar : $(HOST_OUT)/tradefed/loganalysis.jar
+
 #######################################################
 include $(CLEAR_VARS)
 
diff --git a/remote/Android.bp b/remote/Android.bp
index 2d23c23..523276f 100644
--- a/remote/Android.bp
+++ b/remote/Android.bp
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-tradefed_java_library_host {
+java_library_host {
   name: "tf-remote-client",
   defaults: ["tradefed_defaults"],
 
diff --git a/remote/Android.mk b/remote/Android.mk
new file mode 100644
index 0000000..7c58fc1
--- /dev/null
+++ b/remote/Android.mk
@@ -0,0 +1,25 @@
+# Copyright (C) 2013 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.
+
+LOCAL_PATH := $(call my-dir)
+
+# makefile rules to copy jars to HOST_OUT/tradefed
+# so tradefed.sh can automatically add to classpath
+DEST_JAR := $(HOST_OUT)/tradefed/tf-remote-client.jar
+BUILT_JAR := $(call intermediates-dir-for,JAVA_LIBRARIES,tf-remote-client,HOST)/javalib.jar
+$(DEST_JAR): $(BUILT_JAR)
+	$(copy-file-to-new-target)
+
+# this dependency ensure the above rule will be executed if jar is built
+$(HOST_OUT_JAVA_LIBRARIES)/tf-remote-client.jar : $(DEST_JAR)