This article from http://blog.csdn.net/chenshaoyang0011 reprint please declare the source of the article!
Because we need to study the source code of Android 4.0launcher2, We need to debug the code when necessary, so we need to be able to run the modified
Launcher. Because launcher is a built-in Android Application, you can build an android source code development environment for debugging and development.
Linux and MACOs. For most programmers who are used to the windows and eclipse development environments, it is best to develop and debug in eclipse.
. Here we will share with you the steps to build the launcher development environment using eclipse in windows. The eclipse version I use is 3.6.2 and ADT.
Listen 0.2. The process may be slightly different from yours, but the basic process is the same.
1. Create a project and select file ---> New -----> project... ----> Android project from existing code ----> browse ----> locate the source code path -----
> Finish. The project is created. After the project is created, you need to change the SDK version, right-click the project, and choose Properties ----> Android ---> android4.0.3 (API version
Above 15) ---> OK. However, at this time, the project still cannot be run, mainly because some APIs not made public by Android are called in the source code. Compile
Android source code, because some compiled class. Jar files are used, so that this part of the API can be used. If the source code is not compiled, Google.
Many ~~~~ For the convenience of users, the launcher source code and JAR File Download and click to open the link
2. Add the JAR file to be used. After the source code is compiled, the out folder is generated in the root directory. The file we need is located
Out/target/common/obj/java_libraries directory. The jar files to be added include:
(1) framework_intermediates/classes. Jar
: This is mainly the android framework class.
(2) android-common_intermediates/classes. Jar
: This includes the com. Android. Common. Search Class.
(3) core_intermediates/classes. Jar
: This package contains the Dalvik. system. vmruntime class.
Right-click the project and select
Build path --> Configure build path --> libraries --> Add library --> User Libraries
--> New... --> enter a name (for example, debug_launcher) --> OK
--> Add jar... ---> Add the jar files required above. Imported
Select order and export in build path, and route debug_launcher to android4.0.3 (the SDK version I selected ).
3. Next, open androidmanifest. xml first. If the following code is not available, add:
[Java]
View plaincopyprint?
- <Uses-SDK
- Android: minsdkversion = "13"
- Android: targetsdkversion = "15"/>
<uses-sdk android:minSdkVersion="13" android:targetSdkVersion="15" />
Minsdkversion can be a value greater than 13. Likewise, targetsdkversion must be at least 15. If there is still an error, it is generally caused by the SDK version.
A later version of SDK can solve the problem.
4. Add android-support-v13.jar
This file path (your SDK directory) \ extras \ Android \ Compatibility \ v13. If not, download it through SDK manager. After finding the file,
Copy it to the Lib folder under the root directory of the project (create one if not), and select build
Path ---> Configure build path --> Add
Jars... ---> select android-support-v13.jar
5. If there is still an error, it is generally caused by the SDK version. You can change it to a later version. In this case, there should be no errors in the project. However
It cannot be run on the simulator at this time. You need to modify the package name. First, right-click the package name and select refactor
--> Rename --> enter the modified package name. Next, right
Key Project, select Android tools --> rename Android package, and enter the modified package name. View activity,
Whether the path of the author er and provider is correct; otherwise, replace it with the correct path. After all are replaced, the Red Cross forks in the project will be gone. If there are still errors, if
There are layout file errors. Most of them are namespaces. Replace the namespace. If it is an error in the Java file, if it is an SDK version problem, replace it with the latest version.
You can delete the Import Statement to re-import the r file. In this way, there should be no errors.
6. (optional) Modify database_name and authority in launcherprovider
[Java]
View plaincopyprint?
- // Change it to your own name
- Database_name = "launcherdebug. DB"
// Change it to your own name database_name = "launcherdebug. DB"
[Java]
View plaincopyprint?
- Authority = "com. Android. launcherdebug. Settings"
AUTHORITY = "com.android.launcherdebug.settings"
Then modify the provider and modify the following code:
[Java]
View plaincopyprint?
- <Provider
- ......
- Android: Authorities = "com. Android. launcher. Settings"
- .../>
<provider ...... android:authorities="com.android.launcher.settings" ...... />
Changed:
[Java]
View plaincopyprint?
- <Provider
- ...... // Must be consistent with launcherprovider. Authority
- Android: Authorities = "com. CSY. testlauncher. Settings"
- .../>
<Provider... // must be consistent with launcherprovider. Authority Android: Authorities = "com. CSY. testlauncher. Settings".../>
Next, modify the custom permission in androidmanifest. xml and modify the package name prefix, as shown in figure
[Java]
View plaincopyprint?
- <Permission
- Android: Name = "com. Android. launcher. install_shortcut"
- .../>
<permission android:name="com.android.launcher.INSTALL_SHORTCUT" ....../>
Changed:
[Java]
View plaincopyprint?
- <Permission
- Android: Name = "com. Android. launcherdebug. install_shortcut"
- .../>
<permission android:name="com.android.launcherdebug.INSTALL_SHORTCUT" ...... />
So far, the entire project can be compiled and run smoothly.