1. Preface
After the detailed explanation of a total of eight articles in "debugging system applications with Android Studio - TvSettings", I believe you have been able to make most of Android MK control system APK source code, transplanted into a project file that can be compiled and debugged with AS.
Taking advantage of the hot iron, we will continue to transplant several APK systems. I believe we will encounter various problems. This paper begins to transplant the system application of LiveTV.
Note: aosp source code is the android system source code. The latest version is android 12.0-beta-1 (S).
2. Basic ideas
- Get LiveTV source code
- Android. Live TV analysis MK file
- Create a new project with the same name using AS
- Copy the src and res files into the project
- Add dependency
- Resolve compilation errors
- Installation and commissioning
- be accomplished
Students without foundation, please read the first batch of articles in this series first. There are detailed pictures and texts in it. Because the methods are the same, only the necessary description is made downstairs
TvSettings for debugging system applications using Android Studio (I): Migration
Using Android Studio to debug system application TvSettings (2): build gradle
Using Android Studio to debug system application TvSettings (3): first compilation
3. Commissioning platform
- Software version: android P(9.0)
- Development board: MediaTek 9652(ARM)
- Product: android smart TV
- Note: you can also use your own mobile phone or android simulator in the same way; At the same time, you need to prepare a package of AOSP source code or the public android source code supporting the development board.
4. Obtain App source code
- aosp_tv\packages\apps\TV (AOSP is the original version of Google. Students without development platform can try this version for simulator)
- aosp_tv\vendor\mediatek\proprietary_tv\open\packages\apps\LiveTV (MTK original, using the source code of this package)
5. Analysis configuration file
5.1 analysis target document
Path: aosp_tv\vendor\mediatek\proprietary_tv\open\packages\apps\LiveTV
- LiveTV\Android.mk
- LiveTV\AndroidManifest.xml
5.2 analysis results
LiveTV\AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mediatek.wwtv.tvcenter" -> Package name ......Omit /> <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="28" /> -> API/SDK LV For 28 ......Omit
.
LiveTV\Android.mk
ifeq "$(MSTAR_BSP)" "true" LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_DEX_PREOPT:=false LOCAL_STATIC_JAVA_LIBRARIES += com.mediatek.mtkaudiopatchmanager -> implementation files('../libs/com.mediatek.mtkaudiopatchmanager.jar') LOCAL_STATIC_JAVA_LIBRARIES += \ -> MTK specific,by implementation static link library com.mediatek.support.sharecode \ -> implementation files('../libs/com.mediatek.support.sharecode.jar') com.mediatek.support.tv \ -> implementation files('../libs/com.mediatek.support.tv.jar') volley \ -> implementation files('../libs/volley.jar') com.mediatek.dm \ -> implementation files('../libs/com.mediatek.dm.jar') com.mediatek.tv.ini -> implementation files('../libs/com.mediatek.tv.ini.jar') LOCAL_STATIC_ANDROID_LIBRARIES := \ -->android.support Support library, for implementation Static link android-support-v7-recyclerview \ -> implementation 'com.android.support:recyclerview-v7:28.0.0' android-support-v7-preference \ -> implementation 'com.android.support:preference-v7:28.0.0' android-support-v7-appcompat \ -> implementation 'com.android.support:appcompat-v7:28.0.0' android-support-v7-palette \ -> implementation 'com.android.support:palette-v7:28.0.0' android-support-v14-preference \ -> implementation 'com.android.support:preference-v14:28.0.0' android-support-v17-preference-leanback \ -> implementation 'com.android.support:preference-leanback-v17:28.0.0' android-support-v17-leanback \ -> implementation 'com.android.support:leanback-v17:28.0.0' android-support-tv-provider \ -> implementation 'com.android.support:support-tv-provider:28.0.0' com.mediatek.tv.agent \ -> implementation files('../libs/com.mediatek.tv.agent.jar') android-arch-lifecycle-extensions -> implementation 'android.arch.lifecycle:extensions:1.1.1' LOCAL_RESOURCE_DIR := \ $(LOCAL_PATH)/res LOCAL_USE_AAPT2 := true LOCAL_SRC_FILES := \ $(call all-java-files-under, src) LOCAL_SRC_FILES += ../../../public_inc/android/common/FileSystemPath.java ->Of other directories that need to be included java file LOCAL_PRIVATE_PLATFORM_APIS := true ->use sdk of hide of api To compile,So we need to compile it ourselves framework.jar LOCAL_PACKAGE_NAME := LiveTV -> APK Name, and LiveTV.apk LOCAL_CERTIFICATE := platform -> Use system signature LOCAL_PRIVILEGED_MODULE := true -> Install to system/priv-app Under the directory include $(BUILD_PACKAGE) -> Compile into APK file endif
6. Build the Android Studio project of LiveTv
Because it is the second article on transplantation, the same steps will not be described in detail. If you have any questions, you can refer to the relevant articles in this column.
6.1 basic steps
- Android Studio -> Create New Project->Android Tv->NoActivity
- Fill in the project information and create a LiveTV project according to the analysis results of the upstairs configuration
- Delete the res and src files in the new LiveTV project
- AOSP_ tv\vendor\mediatek\proprietary_ TV \ open \ packages \ apps \ src, res, androidmanifest. In livetv Copy the XML file to the corresponding directory of the new AS project
- Git initializes the LiveTV project and submits a modification; In the following steps, submit every time you solve an error
- According to upstairs analysis, edit build Gradle and other dependencies and configurations
- Compile - > resolve error - > compile passed
- Sign - > Run - > resolve run errors
- be accomplished!
6.2 created directory structure
Note: org and org represent the original version
szhou@yanfa-zs-502143:/mnt/d/szhou/note/android_02/source_as/LiveTV$ tree -L 5 . ├── app │ ├── build.gradle │ ├── libs │ ├── proguard-rules.pro │ └── src │ └── main │ ├── AndroidManifest.xml ->from aosp_tv\vendor\mediatek\proprietary_tv\open\packages\apps\LiveTV\AndroidManifest.xml copy │ ├── assets │ │ ├── licenses.html │ │ ├── music │ │ └── rating_sources.html │ ├── java │ │ └── com --> from aosp_tv\vendor\mediatek\proprietary_tv\open\packages\apps\LiveTV\src\com\* copy │ └── res -> l from aosp_tv\vendor\mediatek\proprietary_tv\open\packages\apps\LiveTV\res copy │ ├── anim │ ├── animator │ ├── color │ ├── drawable │ ├── drawable-hdpi │ ├── drawable-ldpi │ ├── drawable-mdpi │ ├── drawable-xhdpi │ ├── drawable-xxhdpi │ ├── font │ ├── layout │ ├── raw │ ├── values │ ├── values-hdpi │ ├── values-land │ ├── values-xhdpi │ └── xml ├── build.gradle ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle 28 directories, 13 files szhou@yanfa-zs-502143:/mnt/d/szhou/note/android_02/source_as/LiveTV$
6.3 modify app / build gradle
Edit app / build according to the analysis results in 5.2 above Gradle file, and add some common wrong configuration items of TvSettings transplanted before and the configuration of system signature. The final effect is as follows.
app/build. The full text of gradle is modified as follows
plugins { id 'com.android.application' } android { compileSdkVersion 28 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.mediatek.wwtv.tvcenter" minSdkVersion 28 targetSdkVersion 28 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } //Solve the jdk compatibility problem. By default, it is version 1.7 and does not support lamda expressions compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } //System signature file signingConfigs { release { storeFile file("../../keystore/mh/platform.jks") storePassword 'android' keyAlias 'platform' keyPassword 'android' } debug { storeFile file("../../keystore/mh/platform.jks") storePassword 'android' keyAlias 'platform' keyPassword 'android' } } } dependencies { //Necessary jar package to replace android.com of SDK Jar, because you need to use hide system functions compileOnly files('libs/framework.jar') //Press Android The analysis results of MK will depend on this //1. LOCAL_STATIC_JAVA_LIBRARIES of the Android.mk //The following MTK specific dependencies should be copied from the compiled source directory and stored as app/libs implementation files('libs/com.mediatek.mtkaudiopatchmanager.jar') //LOCAL_STATIC_JAVA_LIBRARIES += com.mediatek.mtkaudiopatchmanager implementation files('libs/com.mediatek.support.sharecode.jar') // com.mediatek.support.sharecode //implementation files('libs/com.mediatek.support.tv.jar') //com. mediatek. support. There are duplicate classes in TV compilation. This item is temporarily removed implementation files('libs/volley.jar') //volley implementation files('libs/com.mediatek.dm.jar') //com.mediatek.dm implementation files('libs/com.mediatek.tv.ini.jar') //com.mediatek.tv.ini //2. LOCAL_STATIC_ANDROID_LIBRARIES of the Android.mk //The following Android Support items can be queried on Baidu or the official Android website implementation 'com.android.support:recyclerview-v7:28.0.0' //android-support-v7-recyclerview implementation 'com.android.support:preference-v7:28.0.0' //android-support-v7-preference implementation 'com.android.support:appcompat-v7:28.0.0' //android-support-v7-appcompat implementation 'com.android.support:palette-v7:28.0.0' //android-support-v7-palette implementation 'com.android.support:preference-v14:28.0.0' //android-support-v14-preference implementation 'com.android.support:preference-leanback-v17:28.0.0' //android-support-v17-preference-leanback implementation 'com.android.support:leanback-v17:28.0.0' //android-support-v17-leanback implementation 'com.android.support:support-tv-provider:28.0.0' //android-support-tv-provider //implementation files('libs/com.mediatek.tv.agent.jar') //com.mediatek.tv.agent; Duplicate classes appear during compilation. This item is temporarily removed implementation 'android.arch.lifecycle:extensions:1.1.1' //android-arch-lifecycle-extensions }
6.4 modify livetv / build gradle
Add the following statement to add the framework Set the jar priority to the highest and set it to the default SDK Jar was previously referenced. Note the path of jar: APP / LIBS / framework Jar. If there is a write error, the classes cannot be found, and these classes are used by the framework Jar contains.
allprojects { //Prompt framework Priority of jar gradle.projectsEvaluated { tasks.withType(JavaCompile) { // If there are multiple jars that need to be upgraded, separate them with semicolons, such as jar / framework jar; jar/core-all. jar; options.compilerArgs.add('-Xbootclasspath/p:app/libs/framework.jar;') } } }
6.5 JAR package added
The following JAR package, from AOSP_ tv\out\target\common\obj\JAVA_ Available in the libraries \ directory, you can view the previous relevant articles to understand the detailed process.
szhou@yanfa-zs-502143:/mnt/d/szhou/note/android_02/source_as/LiveTV/app$ tree -L 2 libs libs ├── com.mediatek.dm.jar ├── com.mediatek.mtkaudiopatchmanager.jar ├── com.mediatek.support.sharecode.jar ├── com.mediatek.support.tv.jar ├── com.mediatek.tv.agent.jar ├── com.mediatek.tv.ini.jar ├── framework.jar └── volley.jar 0 directories, 8 files szhou@yanfa-zs-502143:/mnt/d/szhou/note/android_02/source_as/LiveTV/app$
6.6 compilation passed
7. Deploy, test and resolve runtime errors
7.1 preparation before deployment
- This paper uses the adb debugging of the local network, so first connect the development board to the local LAN
- Every time you connect to the development board, you need to start the abdd service of the board and input commands through the serial port
- For each deployment, you need to manually delete the files under system / priv app / livetv /
- Because LiveTV is android:persistent = "true", it cannot be installed directly during debugging. You can set it to android:persistent = "false" first
- After that, you can directly use AS and click run 'app' or debug 'app'
7.2 strange NoSuchMethodError: No virtual method readMultiPsStrValue error
7.2.1 error printing
--------- beginning of crash 06-08 09:55:49.884 5430 5430 E AndroidRuntime: Process: com.mediatek.wwtv.tvcenter, PID: 5430 06-08 09:55:49.884 5430 5430 E AndroidRuntime: java.lang.NoSuchMethodError: No virtual method readMultiPsStrValue(Ljava/lang/String;)Ljava/lang/String; in class Lcom/mediatek/wwtv/tvcenter/util/SaveValue; or its super classes (declaration of 'com.mediatek.wwtv.tvcenter.util.SaveValue' appears in /system/priv-app/LiveTV_ZKJG/LiveTV_ZKJG.apk) ...... Omit
7.2.2 cause analysis
- In essence, the JVM cannot find a specific method readMultiPsStrValue of a class, resulting in an error
- There may also be an inconsistency due to the version of the class that contains this readMultiPsStrValue method
- In the case of this article, this readMultiPsStrValue method is my custom method SaveValue readMultiPsStrValue(), there is no version inconsistency. Through decompiling APK, it is found that SaveValue is prefixed with C0005SaveValue. It is judged that the problem is caused by the unclean environment, because APK does not have this problem if it is integrated into the system image and burned.
7.2.3 analysis process
- Decompile the version compiled by Android Studio and find that the custom class SaveValue is renamed C0005 SaveValue
- Decompile Android MK integrates the compiled version. It is found that the user-defined class SaveValue has not been renamed
7.2.4 conclusion
- The JVM could not find savevalue Readmultipsstrvalue because it has been renamed
- Solution: Rename SaveValue to SaveValueT1. The name of this class is too simple. I don't know if this is the reason. Change the name and recompile to solve the problem;
- This problem is only caused by repeated installation. During the test, it is suspected that the problem is caused by the unclean LiveTV of the uninstalled system. Follow up research will be carried out
7.2.5 other errors
Others are relatively simple mistakes, which have been encountered in the previous articles. If you have trouble, you can read the previous articles or exchange private letters~
.
7.2.5 share the picture of victory
8. Series of articles
TvSettings for debugging system applications using Android Studio (I): Migration
Using Android Studio to debug system application TvSettings (2): build gradle
Using Android Studio to debug system application TvSettings (3): first compilation
TvSettings for debugging system applications using Android Studio (4): porting SettingsLib module
Series column:
https://blog.csdn.net/yyzsyx/category_11101198.html
.
9. Conclusion
It's another two-day experiment. Since the previous articles in this series have explained a lot, it's much easier to write a summary this time. Ha ha~
Interest is a powerful driving force, I hope you like ~!