How do I import the system UI to Android studio step by step

Keywords: Android Gradle Java Eclipse

Next, I will introduce the system UI to Android studio step by step.

Modify the code of the relevant modules of the system. If it's a small modification, it's OK. If it needs more changes, it's best to import the source code into Android studio to modify. The modification efficiency will be improved a lot.

This document is developed for the following points:

1. Download the system UI source code;

Second, import the system UI code into Eclipse and export the project gradle file in Eclipse;

3. Import the system UI code into Android studio;

IV. problems encountered in the import process and solutions;

The focus will be on the fourth part, problems encountered and solutions.

 

1, Download system UI source code

The system UI code can be downloaded directly to the local Android source code under the framewrite / bace / packages / directory.

 

2, Import the system UI code into Eclipse and export the project gradle file in Eclipse

Our ultimate goal is to import the system UI code into Android studio. The reason why we first import the project into eclipse is that eclipse helps us generate the gradle files needed by the project. Android studio projects are built by gradle. With this gradle file, we can import Android studio next.

Exporting gradle files is also very simple. Select our project, right-click, select Export, select generate grade build files, and then continue to next.

    

 

3, Import system UI code into Android studio

With the exported grade file in the second part above, you can open Android studio, find the project directory, and import the project.

After importing the project, there will be an error report, which must be normal, otherwise there will be no content in the fourth part. Note the version of gradle here. The version of gradle exported from eclipse may be older. This needs to be modified according to your own needs and prompted errors. I changed the version of the gradle plug-in to 3.5.0

 

       

(project directory structure after importing into Android stuido)

 

4, Problems encountered in the import process and Solutions

The trouble of importing the code of Android source module into Android studio is that the code of the source module may involve many related resources. The so-called resources are jar s or other classes of the system.

1) check what resources Android.mk involves

The compilation of source code relies on. MK to compile. Check Android.mk, which can help us roughly understand what external resources this project will use.

  LOCAL_STATIC_ANDROID_LIBRARIES In it, you need to package and compile apk Of jar package

 ----------------
    LOCAL_STATIC_ANDROID_LIBRARIES := \
    SystemUIPluginLib \
    SystemUISharedLib \
    android-support-car \
    android-support-v4 \
    android-support-v7-recyclerview \
    android-support-v7-preference \
    android-support-v7-appcompat \
    android-support-v7-mediarouter \
    android-support-v7-palette \
    android-support-v14-preference \
    android-support-v17-leanback \
    android-slices-core \
    android-slices-view \
    android-slices-builders \
    android-arch-core-runtime \
    android-arch-lifecycle-extensions \
LOCAL_JAVA_LIBRARIES  Inside jar,It can only be referenced when compiling, and does not need to be packaged apk,These ones here jar It's the system itself jar
-----------------

LOCAL_JAVA_LIBRARIES := telephony-ext \
    telephony-common \
    android.car \
    ims-common

2) import the required jar package into the project

After checking the contents of Android.mk, we need to import the relevant jar package into the project. OK, how to find these jar packages.

From the content of Android.mk, we can see that there are two types of jar packages, one needs to be packaged into apk, the other only needs to be referenced in the compilation phase. When we are looking for the bag, we will come in two situations.

The jar referenced in local static Android libraries can be found in this path:

Here is the path of Android x.annotation_annotation.jar,
Other jar packages can be found in the same way, in. / out / Soong /. Mediates / prebuilds / SDK / current directory

------------------
./out/soong/.intermediates/prebuilts/sdk/current/androidx/androidx.annotation_annotation/android_common/turbine-combined/androidx.annotation_annotation.jar

The jar referenced in local Java libraries can be found in the out / target / project /.. / system / framework / directory.

 

3) problem: different jar packages imported contain the same content

There is a problem with the jars found in the above way, that is, different jar packages basically contain the same content. An error of Duplicate class will be reported during compilation.

From the following figure, we can see that the three imported jar s contain the same android.arch. *, android.support. * and other classes, which results in repeated compilation of direct report classes.

       

Many solutions have been found on the Internet to solve this problem. Basically, when importing jar packages, we use the exclude field to remove duplicate group s or module s. However, when I try, I will directly prompt that there is no exclude in the gradle DSL.

I always feel that the jar package I am looking for is wrong, and it should not contain the same content. If you know the reason, you can tell me. Thank you very much!

 

4) modify the jar package, delete the duplicate contents of the jar package, and then regenerate the jar package

There is no other clue later. Try to delete the repeated contents of the jar package, and then recombine the jar package.

The specific method is to change the suffix of the jar package to zip, decompress it, delete the duplicate content (I just deleted the relevant duplicate class here, the original META-INF folder did not move), and then regenerate the jar through the jar cvf command.

This process is to continuously delete duplicate content, then export and compile.

5) Problem: More than one file was found

During compilation, I also encountered the following problem: META-INF / * * * content has multiple places, which I think may be related to the content in point 4 above. When I delete duplicate packages, I still keep the original META-INF folder unchanged.  

More than one file was found with OS independent path 'META-INF/androidx.legacy_legacy-support-core-ui.version'

This problem can be solved by adding packagingOptions {...}. Add it in the project's build.gradle file. Here's what I added, and I'll add it if there are many.

android {

    compileSdkVersion 28

    defaultConfig {
        applicationId "com.android.systemui"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 29
    }

   
    packagingOptions {
        exclude 'META-INF/androidx.mediarouter_mediarouter.version'
        exclude 'META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version'
        exclude 'META-INF/androidx.lifecycle_lifecycle-livedata-core.version'
        exclude 'META-INF/androidx.appcompat_appcompat.version'
        exclude 'META-INF/androidx.swiperefreshlayout_swiperefreshlayout.version'
        exclude 'META-INF/androidx.cursoradapter_cursoradapter.version'
        exclude 'META-INF/androidx.media_media.version'
        exclude 'META-INF/androidx.drawerlayout_drawerlayout.version'
        exclude 'META-INF/androidx.print_print.version'
        exclude 'META-INF/androidx.versionedparcelable_versionedparcelable.version'
        exclude 'META-INF/androidx.interpolator_interpolator.version'
        exclude 'META-INF/androidx.palette_palette.version'
        exclude 'META-INF/androidx.fragment_fragment.version'
        exclude 'META-INF/androidx.customview_customview.version'
        exclude 'META-INF/androidx.documentfile_documentfile.version'
        exclude 'META-INF/androidx.vectordrawable_vectordrawable.version'
        exclude 'META-INF/androidx.legacy_legacy-support-core-utils.version'
        exclude 'META-INF/androidx.loader_loader.version'
        exclude 'META-INF/androidx.lifecycle_lifecycle-runtime.version'
        exclude 'META-INF/androidx.viewpager_viewpager.version'
        exclude 'META-INF/androidx.asynclayoutinflater_asynclayoutinflater.version'
        exclude 'META-INF/androidx.lifecycle_lifecycle-viewmodel.version'
        exclude 'META-INF/androidx.recyclerview_recyclerview.version'
        exclude 'META-INF/androidx.core_core.version'
        exclude 'META-INF/androidx.arch.core_core-runtime.version'
        exclude 'META-INF/androidx.vectordrawable_vectordrawable-animated.version'
        exclude 'META-INF/androidx.slidingpanelayout_slidingpanelayout.version'
        exclude 'META-INF/androidx.slice_slice-core.version'
        exclude 'META-INF/androidx.coordinatorlayout_coordinatorlayout.version'
        exclude 'META-INF/androidx.legacy_legacy-support-core-ui.version'
    }
}

6) problem: adb push apk enters, restarts, and prompts permission error

Error prompt: android.permission.read'contacts permission is required. This permission has been applied in the manifest. Refer to later https://blog.csdn.net/grindstone_fos/article/details/53924295 The provided method is solved.

The method is to execute adb naming and give corresponding permissions. I have encountered two permissions that need to be executed in the following way.

         adb shell pm grant "com.android.systemui" "android.permission.READ_CONTACTS"
         adb shell pm grant "com.android.systemui" "android.permission.READ_EXTERNAL_STORAGE"

Process: com.android.systemui, PID: 8064
           
android.view.InflateException: Binary XML file line #87:
 uid=10014 needs permission android.permission.READ_CONTACTS to read lock_screen_owner_info_enabled for user 0

7) Problem: prompt resource not found

Finally, we solved the above problems. Next, we reported a problem that the resource could not be found. I didn't find out the reason for this. I temporarily shielded the code I called.

 

	Line 1145: 12-28 14:27:52.209 E/AndroidRuntime( 2422): FATAL EXCEPTION: main
	Line 1146: 12-28 14:27:52.209 E/AndroidRuntime( 2422): Process: com.android.systemui, PID: 2422
	Line 1147: 12-28 14:27:52.209 E/AndroidRuntime( 2422): android.content.res.Resources$NotFoundException: Resource ID #0x0
	Line 1148: 12-28 14:27:52.209 E/AndroidRuntime( 2422): 	at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
	Line 1149: 12-28 14:27:52.209 E/AndroidRuntime( 2422): 	at android.content.res.Resources.getDimensionPixelSize(Resources.java:727)
	Line 1150: 12-28 14:27:52.209 E/AndroidRuntime( 2422): 	at androidx.slice.widget.ListContent.<init>(ListContent.java:103)
	Line 1151: 12-28 14:27:52.209 E/AndroidRuntime( 2422): 	at androidx.slice.widget.ListContent.<init>(ListContent.java:88)
	Line 1152: 12-28 14:27:52.209 E/AndroidRuntime( 2422): 	at com.android.keyguard.KeyguardSliceView.showSlice(KeyguardSliceView.java:161)
	Line 1153: 12-28 14:27:52.209 E/AndroidRuntime( 2422): 	at com.android.keyguard.KeyguardSliceView.onChanged(KeyguardSliceView.java:343)

 

8) Problem: Android runtime null pointer exception

    A null pointer exception was reported in OverviewProxyService.java. The obtained mRecentsComponentName is null. That is to say, through mcontext.getstring (COM. Android. Internal. R.string. Config ﹣ recentscomponentname), the corresponding resource cannot be obtained. Then, the content of string is directly written in.

  

 

Written in the back

It took a lot of time to guide the project, but fortunately it didn't give up~~

 

------- spring at 21:31 on February 4, 2020

Want to contact me, pay attention to my personal public number, the public number will record their own development, and daily life, hope to communicate with more small partners ~ ~

Published 41 original articles, won praise 8, visited 80000+
Private letter follow

Posted by deadlyp99 on Tue, 04 Feb 2020 05:44:56 -0800