美文网首页
android 10 frameworks 中调用第三方jar

android 10 frameworks 中调用第三方jar

作者: gale_小米 | 来源:发表于2021-12-21 19:02 被阅读0次

1.客制需求,但是没有直接烧写imei的工具,客制应用又需要读取imei的值
(内置客户授权信息,更改imei读取方法,采用内置.xlsx文件的方式)

2.使用的poi 解析方式(aa-poi-3.10-min-0.1.5.jar,aa-poi-ooxml-schemas-3.10-reduced-more-0.1.5.jar)

3.需要把jar导入到framework供系统调用

@SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236).
    @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
    public String getImei(int slotIndex) {
        ITelephony telephony = getITelephony();
        if (telephony == null) return null;
        return xxx.getCustomKey("key","path");
        /*try {
            return telephony.getImeiForSlot(slotIndex, getOpPackageName());
        } catch (RemoteException ex) {
            return null;
        } catch (NullPointerException ex) {
            return null;
        }*/
    }

4.参考系统内置 kxml2-2.3.0.jar(\android\prebuilts\misc\common\kxml2\kxml2-2.3.0.jar) 方式导入上述jar文件,
在同级目录下新建poi和ooxml文件夹,导入jar和配置Android.bp文件
poi\Android.bp

Index: poi\Android.bp
java_import_host {
    name: "poi",
    jars: ["aa-poi-3.10-min-0.1.5.jar"],
    installable: true,
}
java_import {
    name: "poi-android",
    jars: ["aa-poi-3.10-min-0.1.5.jar"],
}
Index: ooxml\Android.bp
java_import_host {
    name: "ooxml",
    jars: ["aa-poi-ooxml-schemas-3.10-reduced-more-0.1.5.jar"],
    installable: true,
}
java_import {
    name: "ooxml-android",
    jars: ["aa-poi-ooxml-schemas-3.10-reduced-more-0.1.5.jar"],
}

jar配置完成再out\soong.intermediates\prebuilts\misc\common\下面可以看到对应的文件库

5.然后在对应的位置frameworks/base/Android.bp添加引用

Index: frameworks/base/Android.bp
 static_libs: [
       ...
        "fo_ota_lib",
        "ooxml-android",
        "poi-android",
    ],

Index: development/build/Android.bp
===================================================================
--- development/build/Android.bp    (revision 11487)
+++ development/build/Android.bp    (working copy)
@@ -35,6 +35,8 @@
     ],
     libs: [
         "stub-annotations",
+        "ooxml-android",
+        "poi-android",
     ],
     static_libs: [
         "private-stub-annotations-jar",
@@ -54,6 +56,8 @@
     ],
     libs: [
         "stub-annotations",
+        "ooxml-android",
+        "poi-android",
     ],
     static_libs: [
         "private-stub-annotations-jar",
@@ -73,6 +77,8 @@
     ],
     libs: [
         "stub-annotations",
+        "ooxml-android",
+        "poi-android",
     ],
     static_libs: [
         "private-stub-annotations-jar",

5.添加白名单

Index: build/make/core/tasks/check_boot_jars/package_whitelist.txt
===================================================================
--- build/make/core/tasks/check_boot_jars/package_whitelist.txt (revision 11487)
+++ build/make/core/tasks/check_boot_jars/package_whitelist.txt (working copy)
@@ -236,6 +236,18 @@
 org\.apache\.xalan\.transformer
 org\.apache\.xalan\.xslt
+# aa-poi-3.10-min-0.1.5.jar and aa-poi-ooxml-schemas-3.10-reduced-more-0.1.5.jar
+aavax\.xml.*
+schemasMicrosoftComVml.*
+rg\.openxmlformats\.schemas.*
+schemasMicrosoftComOfficeExcel.*
+schemasMicrosoftComOfficeOffice.*
+schemasMicrosoftComOfficePowerpoint.*
+schemasMicrosoftComOfficeWord.*
+org.*
+repackage.*
+schemaorg_apache_xmlbeans.*
+
 ###################################################
 # Packages in the google namespace across all bootclasspath jars.
 com\.google\.android\..*

6.更新api (make update-api)

******************************
You have tried to change the 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-api
      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************

Index: frameworks/base/api/current.txt
===================================================================
--- frameworks/base/api/current.txt (revision 11487)
+++ frameworks/base/api/current.txt (working copy)
@@ -44593,6 +44593,13 @@
     field public static final int LISTEN_USER_MOBILE_DATA_STATE = 524288; // 0x80000
   }
 
+  public class xxx{
+    ctor public xxx();
+    method public static Object getCellFormatValue(org.apache.poi.ss.usermodel.Cell);
+    method public static String getCustomKey(String, String);
+    method public static org.apache.poi.ss.usermodel.Workbook readExcel(String);
+  }
+
   public final class RadioAccessSpecifier implements android.os.Parcelable {
     ctor public RadioAccessSpecifier(int, int[], int[]);
     method public int describeContents();
 #
 # A list of all source roots under frameworks/multidex.
 #


7.处理错误

1)问题1. 删除jar包中对应的class类
Check failed: superclass != nullptr Superclass Ljava/awt/Graphics2D; of class Lorg/apache/poi/hssf/usermodel/DummyGraphics2d; 
from dex file "out/soong/.intermediates/frameworks/base/framework/android_common/aligned/framework.jar!classes3.dex" 
was not found. Either the superclass is missing or it appears later in the classpath spec.
...

2)问题2
hiddenapi F 12-21 12:53:16 74081 74081 hiddenapi.cc:538] Check failed: iface != nullptr 
Aborted (core dumped)
12:54:04 ninja failed with: exit status 1
Index: art/tools/hiddenapi/hiddenapi.cc
===================================================================
--- art/tools/hiddenapi/hiddenapi.cc    (revision 11487)
+++ art/tools/hiddenapi/hiddenapi.cc    (working copy)
@@ -535,7 +535,11 @@
       for (const std::string_view& iface_desc : dex_klass.GetInterfaceDescriptors()) {
         HierarchyClass* iface = FindClass(iface_desc);
-        CHECK(iface != nullptr);
+        if (iface == nullptr)
+        {
+         continue;
+        }
+        //CHECK(iface != nullptr);
         klass.AddExtends(*iface);
       }
     }

相关文章

网友评论

      本文标题:android 10 frameworks 中调用第三方jar

      本文链接:https://www.haomeiwen.com/subject/cspxqrtx.html