提取 Android 源码 SDK 中的 jar 包

0. 获取方法

  1. 事先有一套完全编译好的源代码
  2. 在 out/target/common/obj/JAVA_LIBRARIES/ 找
  3. 根据对应模块Android.mk或者Android.bp,定义找对应目录即可
  4. 使用 jar tvf xxx.jar 命令看哪些jar包可以提供给Android Studio 或 Eclipse使用

例如 1. com.android.location.provider.jar 包提取

frameworks/base/location/lib

//
// 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_sdk_library {
    name: "com.android.location.provider",
    srcs: ["java/**/*.java"],
    api_packages: ["com.android.location.provider"],
    srcs_lib: "framework",
    srcs_lib_whitelist_dirs: ["location/java"],
    srcs_lib_whitelist_pkgs: ["com.android.internal.location"],
}

上述中编译生成 com.android.location.provider.jar, 源码一般存放在 JAVA_LIBRARIES,一般后缀 xxx_intermediates, 故我们可以如下搜索

@HZCS18:~$ find out/ -name "com.android.location.provider_intermediates"
out/target/common/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates
out/target/product/k62v1_32_bsp/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates
out/target/product/k62v1_32_bsp/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates/out/target/product/k62v1_32_bsp/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates

即我们在 out/target/common/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates可以找到我们要的 jar 包文件,注意不是 out/target/product/下,因为里面的jar包是dex文件,无法放在Eclipse或Android Studio的libs下使用

su@HZCS18:~/out/target/common/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates$ ls -al
total 192
drwxr-xr-x   5 huazhi.su tcthz  4096 Oct 17 20:28 .
drwxr-xr-x 199 huazhi.su tcthz 16384 Oct 17 14:43 ..
drwxr-xr-x   2 huazhi.su tcthz  4096 Oct 17 16:47 anno
drwxr-xr-x   3 huazhi.su tcthz  4096 Oct 17 16:47 classes
-rw-r--r--   1 huazhi.su tcthz 21401 Oct 17 16:47 classes-combined.jar
-rw-r--r--   1 huazhi.su tcthz 19764 Oct 17 16:47 classes.dex
-rw-r--r--   1 huazhi.su tcthz 21401 Oct 17 16:47 classes-full-debug.jar
-rw-r--r--   1 huazhi.su tcthz 12723 Oct 17 20:27 classes-header.jar
-rw-r--r--   1 huazhi.su tcthz 21817 Oct 17 20:27 classes.jar
drwxr-xr-x   2 huazhi.su tcthz  4096 Oct 17 16:47 dex
-rw-r--r--   1 huazhi.su tcthz 20050 Oct 17 20:28 javalib.jar
-rw-r--r--   1 huazhi.su tcthz 20078 Oct 17 16:47 javalib.jar.unaligned
-rw-r--r--   1 huazhi.su tcthz  1117 Oct 17 16:46 java-source-list
-rw-r--r--   1 huazhi.su tcthz  1117 Oct 17 16:46 java-source-list.tmp
-rw-r--r--   1 huazhi.su tcthz    14 Oct 17 10:16 link_type

接下来使用 jar tvf xxx.jar 看下哪个jar包可以使用

/local/sda/service_code/tokyo_lite/out/target/common/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates$ jar tvf javalib.jar
 19764 Tue Jan 01 00:00:00 CST 2008 classes.dex
    45 Tue Jan 01 00:00:00 CST 2008 META-INF/MANIFEST.MF

user@chuanghangren-Lenovo-Product:/local/sda/service_code/tokyo_lite/out/target/common/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates$ jar tvf classes-full-debug.jar 
     0 Thu Oct 17 16:47:04 CST 2019 META-INF/
    61 Thu Oct 17 16:47:04 CST 2019 META-INF/MANIFEST.MF
  1828 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityChangedEvent.class
  1490 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionEvent.class
   289 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProvider$1.class
   357 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProvider$Sink.class
  3462 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProvider$SinkTransport.class
  3644 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProvider.class
  2227 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProviderClient$1.class
  1110 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProviderClient.class
  2138 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProviderWatcher$1.class
  2080 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ActivityRecognitionProviderWatcher.class
   503 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/FusedProvider.class
  1817 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/GeocodeProvider$1.class
  1246 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/GeocodeProvider.class
  1344 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/GeofenceProvider$1.class
  1348 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/GeofenceProvider.class
   268 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/LocationProviderBase$1.class
  3767 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/LocationProviderBase$Service.class
  6505 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/LocationProviderBase.class
  1361 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/LocationRequestUnbundled.class
  1289 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ProviderPropertiesUnbundled.class
  2006 Thu Oct 17 16:47:04 CST 2019 com/android/location/provider/ProviderRequestUnbundled.class

故我们 com.android.location.provider.jar 可以直接使用 out/target/common/obj/JAVA_LIBRARIES/com.android.location.provider_intermediates/classes-full-debug.jar 的jar包就行

2. 例如 源码获取 framework.jar 的提取

/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar

:/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates$ jar xvf javalib.jar 
已提取: classes.dex
已提取: classes2.dex
已提取: classes3.dex
  已解压: META-INF/MANIFEST.MF
:/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates$ jar xvf classes.jar 
  已解压: vendor/mediatek/hardware/netdagent/V1_0/INetdagent.class
  已解压: vendor/mediatek/hardware/netdagent/V1_0/INetdagent$Stub.class
  已解压: vendor/mediatek/hardware/netdagent/V1_0/INetdagent$Proxy.class
  已创建: vendor/mediatek/hardware/netdagent/V1_0/
  已创建: vendor/mediatek/hardware/netdagent/
  已创建: vendor/mediatek/hardware/
  已创建: vendor/mediatek/
  已创建: vendor/
  .... 很长很长,就不黏贴了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

法迪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值