programing tip

숨겨진 및 내부 API를 사용할 수있는 Android SDK를 어떻게 빌드합니까?

itbloger 2020. 10. 7. 07:25
반응형

숨겨진 및 내부 API를 사용할 수있는 Android SDK를 어떻게 빌드합니까?


숨겨진 내부 API를 포함하도록 Android SDK (또는 android.jar 만)를 다시 빌드하고 싶습니다.

이 문제를 해결하는 방법에 대한 문서 나 토론을 찾을 수 없습니다. cm7을 빌드 할 수있는 Ubuntu CyanogenMod 빌드 환경이 이미 설정되어 있습니다.

이제 make SDK가 SDK를 빌드한다고 읽었지만 @hide를 사용하여 숨김으로 표시된 메서드와 필드를 포함하는 SDK를 빌드하고 싶습니다. 이것이 가능한가?

내가하고 싶은 것은 숨겨진 API를 사용하는 응용 프로그램을 변경하는 것이며이를 다시 빌드하기 위해 수정 된 SDK를 사용하고 싶습니다.


이것이 내가 항상 숨겨진 API를 사용하는 것입니다.

  1. https://sites.google.com/site/hippunosource/home/android/androidnohide-apiwo-shi-yongsuru-rifurekushonha-wei-shi-yong 에서 저장소를 빌드하거나 jar를 다운로드합니다.
  2. 복사 /target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar(framework_all.jar과 같은 이름으로 이름을 바꾸는 것이 좋습니다)
  3. 프로젝트 빌드 경로-> 라이브러리->이 외부 jar를 추가하십시오. 주문 및 내보내기에서 android.jar 이전으로 이동하십시오.

나는 이것에 대해 몇 가지 조사를했고 내 결론은 간단하다 : 이것은 꽤 많은 작업 없이는 할 수 없다. 내가 찾은 내용에 대한 자세한 내용은이 답변의 나머지 부분을 읽으십시오.


android.jar실제로 "공개 API"로 구성 framework.jar되며 장치 core.jar에서 찾을 수 system/frameworks/있습니다. android.jar은 내가 자바 라이브러리 헤더라고 부르는 일종의 것입니다. 실제 바이트 코드의 모든 구현은 단지 a입니다 throw new RuntimeException("stub");. 이것은 당신이 빌드 할 수 있도록합니다 android.jar(예 : Eclipse).하지만 실행은 장치 나 에뮬레이터에서 수행되어야합니다.

Android SDK의 공용 API javadoc 어노테이션 두부 없는 클래스 / 메소드 / 필드로 정의됩니다 @{hide}. 즉, 주석이 추가 되지 않은 모든 것이 SDK에 포함됩니다.

android.jarout/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates있는 DroidDoc 도구에 의해 생성 된 소스에서 빌드 됩니다 build/tools/droiddoc.

DroidDoc 은 실제 Android SDK 문서를 생성하는 도구 (아마도 javadoc 또는 javadoc 사용)입니다. 부작용으로, 아마도 이미 모든 javadoc을 파싱하고 있기 때문에 android.jarSDK에 배포되는 로 컴파일되는 Android 스텁도 분출됩니다 .

따라서 숨겨진 항목을 포함하려면 특정 부분 만 포함하려는 경우 @hide주석을 제거 하고 SDK를 다시 빌드하면됩니다.

그러나 모든 숨겨진 부분을 포함하려면 상황이 훨씬 더 복잡해집니다. 숨겨진 것으로 감지되지 않도록 DroidDoc (관련 소스는에 있음 build/tools/droiddoc/src/Stubs.java)을 수정할 수 있습니다 . 이것은 매우 사소한 일이며 이것을 시도했지만 생성 된 스텁은 전혀 컴파일되지 않습니다.

내 결론은 이것이 단순히 실현 가능하지 않다는 것입니다. 숨겨진 주석을 감지하는 DroidDoc 부분을 제거하면 생성되는 스텁은 단순히 컴파일 할 수 없으며 올바르게 컴파일하려면 상당한 작업이 필요합니다.

그래서 당신의 질문에 대한 나의 대답은 : 아니오, 이것은 많은 일을하지 않고서는 할 수 없습니다. 죄송합니다.


mkstubs도구 에 대한 추가 정보 입니다. SDK 애드온mkstubs 을 빌드 할 때 사용됩니다 . 즉, 공급 업체의 Android SDK 관리자에서 찾을 수있는 애드온입니다. 예를 들어 삼성은 삼성 휴대 전화와 관련된 추가 API를 제공합니다. DroidDoc 스텁 생성 프로세스와 거의 동일하지만 주석을 사용하지 않고 SDK 애드온에서 포함하거나 제외 할 패키지 / 클래스 / 필드를 설명 하는 파일을 사용합니다 .mkstubs@hide.defs

그러나 이것은 Android SDK 빌드가 도구를 사용 하지 않기 때문에 질문과 관련이 없습니다mkstubs . (운수 나쁘게.)


Android 플랫폼에서 * .jar 파일을 재구성 할 수 있습니다.

먼저 ADB를 장치에 연결하십시오. 그런 다음 다음을 실행하십시오.

adb pull /system/framework/core.jar .
adb pull /system/framework/framework.jar .

core.jar표준 자바 라이브러리를 포함 ( java.*)과은 framework.jar(안드로이드 라이브러리를 포함 android.*). 실제 파일은 JAR 형식이 아닌 DEX 형식이므로 아직 사용할 수 없습니다.

dex2jar 와 같은 도구를 사용하여 DEX 형식의 * .jar을 실제 JAR로 변환 할 수 있습니다 .

dex2jar core.jar
dex2jar framework.jar

그런 다음 "외부 JAR 추가 ..."를 사용하여이 jar를 가져옵니다 (Eclipse ADT를 사용한다고 가정).

  • 오른쪽 클릭 Project → Properties → Java Build Path → Libraries → Add External JARs... → ( 위에서 core-dex2jar.jar선택 framework-dex2jar.jar).

이를 통해 내부 및 일부 Java 7 API를 사용할 수 있습니다. (내가 볼 수있는 한 생성 된 APK에는 JAR의 실제 코드가 포함되어 있지 않습니다.)


Lollipop의 경우 흐름이 약간 다릅니다.

  1. Lollipop 기기에서 /system/framework/arm/boot.oat 가져 오기

  2. 'java -jar oat2dex.jar boot boot.oat'사용

  3. dex와 odex라는 두 개의 폴더가 있습니다. dex로 이동하여 'java -jar dex2jar.jar framework.dex'를 만듭니다.
  4. 결과 framework.jar의 이름을 .zip으로 바꾸고 필요한 클래스를 추출하여 찾습니다.
  5. [sdk_path] / platforms / [target_platform]으로 이동하여 android.jar의 압축을 풉니 다 (먼저 이름을 zip으로 바꿉니다).
  6. 추출 된 프레임 워크에서 추출 된 android.jar로 파일을 복사합니다. 그런 다음 zip으로 압축하고 .jar로 이름을 바꿉니다.

추신 : 아마도 'framework_classes2.dex'에 대해 4-6 단계를 반복해야합니다.


DroidCon 2011

여기 Sony Ericson의 Erik Hellman이 숨겨진 Android API에 액세스하는 방법을 설명합니다.

http://vimeo.com/30180393(Hmm 링크가 작동하지 않는 것 같습니다).

고토 DroidCon 웹 페이지 일 2 로 스크롤 아래 숨겨진 API 10:15 사용 하고 당신이 거기에 그것을 볼 수 있습니다.

링크가 죽고 있습니다!

나는 이것을 찾았습니다 : http://skillsmatter.com/podcast/os-mobile-server/hidden-api dunno 얼마나 오래 걸릴지

The official APIs in the Android SDK is usually sufficient for most normal applications. However, there are sometimes situations where a developer needs access to the internal system services, APIs and resources that are not published in the official APIs. Fortunately, these APIs are still available through some clever tricks and can often be useful when developing new and innovative solution on top of Android. In this session you will learn how to access and use these hidden and protected APIs, the limitations of their usage and some tips'n'trick on how to use them in a safe and control manner across multiple vendors devices and Android versions. The audience will see several advanced demos that you normally cannot do with Android. Expect a fairly advanced session with lots of insights in the internals of the Android platform.


You can download the modified android.jar to be used as hidden APIs from this repository. Follow the instructions there.


Try to look at this:

The ultimate target of these articles is to give developers the power of Internal and Hidden APIs without using reflection. If you complete all the steps described in next several parts you will be able to use Internal and Hidden APIs as if they were public open APIs. There will be no need for reflection.

But if you’re using these non-public APIs then you should be aware that your application is at great risk. Basically there are no guarantees that APIs will not be broken with next update to Android OS. There are even no guarantees about consistent behavior across devices from different vendors. You are completely on your own.

There are three scenarios you may want to follow:

  1. Enable both internal and hidden APIs (scenario A)
  2. Enable only hidden API (scenario B)
  3. Enable only internal API (scenario C)

Scenario A is a sum of B and C. Scenario B is the easiest one (requires no eclipse ADT plugin modifications).

Scenario A: read parts 1, 2, 3, 4, 5

Scenario B: read parts 1, 2, 3, 5

Scenario C: read parts 1, 2, 3, 4, 5


I once wrote some Groovy scripts for extracting the java files from a repo checkout from http://source.android.com/ and then compiling them without the need for a full toolchain for compiling all the android sources, including the needed other steps (packaging, generating resources etc).

They can be found here:

https://github.com/thoutbeckers/CollectAndroid

But for sure this will need updating for anything after Gingerbread, mostly by setting the correct directories in "rootdirs" in the config file (CollectConfig.groovy).

At the time I regularly used this for development with all of the hidden API and sources (also problematic at the time) available.

As mentioned elsewhere com/android/internal/** will still be hidden in recent versions of ADT due to the access rule aded.


I can't comment but this is basically a comment to @KennyTM's (https://stackoverflow.com/a/13550030/2923406) excellent answer:

If you find yourself with the following error in Eclipse:

The type com.android.internal.util.Predicate cannot be resolved. It is indirectly referenced from required .class   files

(that is, android.internal.* is not available)

Then one possible solution is to apply the same method for /system/framework/framework2.jar. Using the Android Emulator for SDK19 I have this extra jar. On my HTC One there is even a framework3.jar.


Long's answer worked for me, but I was still missing some classes I needed, in particular android.provider.Telephony. I was able to add it like this:

  1. Find where the class is

    $ cd /path/to/out/target/common/obj/JAVA_LIBRARIES
    $ find . | grep "/Telephony.class"
    ./telephony-common_intermediates/classes/android/provider/Telephony.class
    ./android_stubs_current_intermediates/classes/android/provider/Telephony.class
    
  2. Add the new classes and rebuild the framework JAR file

    cd /path/to/temp/folder
    cp -r /path/to/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes .
    cp -r /path/to/out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/classes .
    cd classes
    jar cvf ../framework.jar .
    

Or you can just be lazy and include all of the classes into one giant jar file:

cd /path/to/temp/folder
cp -r /path/to/out/target/common/obj/JAVA_LIBRARIES/*/classes .
cd classes
jar cvf ../framework.jar .

참고URL : https://stackoverflow.com/questions/7888191/how-do-i-build-the-android-sdk-with-hidden-and-internal-apis-available

반응형