找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 6907|回复: 2

【Android】android静默安装/卸载

[复制链接]
发表于 2015-12-18 13:54:47 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
目的:实现利用隐藏api静默安装/卸载apk
条件:必须有 root权限/当前系统签名 之一
工具:android studio/eclipse + adt
文档结构:
D:\PROGRAM FILES\ECLIPSE\INSTALLINBACKGROUNDSAMPLE\SRC
├─android
│  └─content
│      └─pm
│              IPackageDeleteObserver.java
│              IPackageInstallObserver.java

└─com
    └─paulononaka
        │  InstallInBackgroundSample.java
        │
        └─apihelper
                ApplicationManager.java
                OnDeletedPackaged.java
                OnInstalledPackaged.java

代码:
  1. package android.content.pm;

  2. import android.content.Intent;

  3. public interface IPackageDeleteObserver  extends android.os.IInterface {
  4.         public abstract static class Stub extends android.os.Binder implements android.content.pm.IPackageDeleteObserver {
  5.                 public Stub() {
  6.                         throw new RuntimeException("Stub!");
  7.                 }

  8.                 public static android.content.pm.IPackageInstallObserver asInterface(android.os.IBinder obj) {
  9.                         throw new RuntimeException("Stub!");
  10.                 }

  11.                 public android.os.IBinder asBinder() {
  12.                         throw new RuntimeException("Stub!");
  13.                 }

  14.                 public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)
  15.                                 throws android.os.RemoteException {
  16.                         throw new RuntimeException("Stub!");
  17.                 }
  18.         }

  19.     public abstract void packageDeleted(String packageName, int returnCode, String msg)
  20.                     throws android.os.RemoteException;
  21. }

复制代码
  1. package android.content.pm;

  2. import android.content.Intent;

  3. public interface IPackageInstallObserver extends android.os.IInterface {
  4.        
  5.         public abstract static class Stub extends android.os.Binder implements android.content.pm.IPackageInstallObserver {
  6.                 public Stub() {
  7.                         throw new RuntimeException("Stub!");
  8.                 }

  9.                 public static android.content.pm.IPackageInstallObserver asInterface(android.os.IBinder obj) {
  10.                         throw new RuntimeException("Stub!");
  11.                 }

  12.                 public android.os.IBinder asBinder() {
  13.                         throw new RuntimeException("Stub!");
  14.                 }

  15.                 public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)
  16.                                 throws android.os.RemoteException {
  17.                         throw new RuntimeException("Stub!");
  18.                 }
  19.         }

  20.         public abstract void packageInstalled(java.lang.String packageName, int returnCode)
  21.                         throws android.os.RemoteException;
  22. }
复制代码
  1. package com.paulononaka;

  2. import com.paulononaka.apihelper.ApplicationManager;
  3. import com.paulononaka.apihelper.OnInstalledPackaged;

  4. import android.app.Activity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.widget.Button;
  10. import android.widget.TextView;
  11. import android.widget.Toast;

  12. public class InstallInBackgroundSample extends Activity {

  13.         public static final String TAG = "InstallInBackgroundSample";

  14.         @Override
  15.         public void onCreate(Bundle savedInstanceState) {
  16.                 super.onCreate(savedInstanceState);
  17.                 setContentView(R.layout.main);

  18.                 try {
  19.                         final ApplicationManager am = new ApplicationManager(InstallInBackgroundSample.this);
  20.                         am.setOnInstalledPackaged(new OnInstalledPackaged() {

  21.                                 public void packageInstalled(String packageName, int returnCode) {
  22.                                         if (returnCode == ApplicationManager.INSTALL_SUCCEEDED) {
  23.                                                 Log.d(TAG, "Install succeeded");
  24.                                         } else {
  25.                                                 Log.d(TAG, "Install failed: " + returnCode);
  26.                                         }
  27.                                 }
  28.                         });

  29.                         final TextView txtApkFilePath = (TextView) findViewById(R.id.txtApkFilePath);

  30.                         Button btnInstall = (Button) findViewById(R.id.btnInstall);
  31.                         btnInstall.setOnClickListener(new OnClickListener() {

  32.                                 @Override
  33.                                 public void onClick(View arg0) {
  34.                                        
  35.                                         try {
  36.                                                 am.uninstallPackage("com.immomo.momo");
  37.                                                 //am.installPackage(txtApkFilePath.getText().toString());
  38.                                         } catch (Exception e) {
  39.                                                 logError(e);
  40.                                         }
  41.                                 }
  42.                         });
  43.                 } catch (Exception e) {
  44.                         logError(e);
  45.                 }
  46.         }

  47.         private void logError(Exception e) {
  48.                 e.printStackTrace();
  49.                 Toast.makeText(InstallInBackgroundSample.this, R.string.error, Toast.LENGTH_LONG).show();
  50.         }
  51. }
复制代码
  1. package com.paulononaka.apihelper;

  2. import java.io.File;
  3. import java.lang.reflect.InvocationTargetException;
  4. import java.lang.reflect.Method;

  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.pm.IPackageInstallObserver;
  8. import android.content.pm.IPackageDeleteObserver;
  9. import android.content.pm.PackageManager;
  10. import android.net.Uri;
  11. import android.os.RemoteException;

  12. public class ApplicationManager {

  13.         public final int INSTALL_REPLACE_EXISTING = 2;
  14.        
  15.     /**
  16.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  17.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} on success.
  18.      * @hide
  19.      */
  20.     public static final int INSTALL_SUCCEEDED = 1;

  21.     /**
  22.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  23.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package is
  24.      * already installed.
  25.      * @hide
  26.      */
  27.     public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;

  28.     /**
  29.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  30.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package archive
  31.      * file is invalid.
  32.      * @hide
  33.      */
  34.     public static final int INSTALL_FAILED_INVALID_APK = -2;

  35.     /**
  36.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  37.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the URI passed in
  38.      * is invalid.
  39.      * @hide
  40.      */
  41.     public static final int INSTALL_FAILED_INVALID_URI = -3;

  42.     /**
  43.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  44.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package manager
  45.      * service found that the device didn't have enough storage space to install the app.
  46.      * @hide
  47.      */
  48.     public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;

  49.     /**
  50.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  51.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if a
  52.      * package is already installed with the same name.
  53.      * @hide
  54.      */
  55.     public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;

  56.     /**
  57.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  58.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  59.      * the requested shared user does not exist.
  60.      * @hide
  61.      */
  62.     public static final int INSTALL_FAILED_NO_SHARED_USER = -6;

  63.     /**
  64.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  65.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  66.      * a previously installed package of the same name has a different signature
  67.      * than the new package (and the old package's data was not removed).
  68.      * @hide
  69.      */
  70.     public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;

  71.     /**
  72.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  73.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  74.      * the new package is requested a shared user which is already installed on the
  75.      * device and does not have matching signature.
  76.      * @hide
  77.      */
  78.     public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;

  79.     /**
  80.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  81.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  82.      * the new package uses a shared library that is not available.
  83.      * @hide
  84.      */
  85.     public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;

  86.     /**
  87.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  88.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  89.      * the new package uses a shared library that is not available.
  90.      * @hide
  91.      */
  92.     public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;

  93.     /**
  94.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  95.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  96.      * the new package failed while optimizing and validating its dex files,
  97.      * either because there was not enough storage or the validation failed.
  98.      * @hide
  99.      */
  100.     public static final int INSTALL_FAILED_DEXOPT = -11;

  101.     /**
  102.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  103.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  104.      * the new package failed because the current SDK version is older than
  105.      * that required by the package.
  106.      * @hide
  107.      */
  108.     public static final int INSTALL_FAILED_OLDER_SDK = -12;

  109.     /**
  110.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  111.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  112.      * the new package failed because it contains a content provider with the
  113.      * same authority as a provider already installed in the system.
  114.      * @hide
  115.      */
  116.     public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;

  117.     /**
  118.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  119.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  120.      * the new package failed because the current SDK version is newer than
  121.      * that required by the package.
  122.      * @hide
  123.      */
  124.     public static final int INSTALL_FAILED_NEWER_SDK = -14;

  125.     /**
  126.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  127.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  128.      * the new package failed because it has specified that it is a test-only
  129.      * package and the caller has not supplied the {@link #INSTALL_ALLOW_TEST}
  130.      * flag.
  131.      * @hide
  132.      */
  133.     public static final int INSTALL_FAILED_TEST_ONLY = -15;

  134.     /**
  135.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  136.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  137.      * the package being installed contains native code, but none that is
  138.      * compatible with the the device's CPU_ABI.
  139.      * @hide
  140.      */
  141.     public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;

  142.     /**
  143.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  144.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  145.      * the new package uses a feature that is not available.
  146.      * @hide
  147.      */
  148.     public static final int INSTALL_FAILED_MISSING_FEATURE = -17;

  149.     // ------ Errors related to sdcard
  150.     /**
  151.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  152.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  153.      * a secure container mount point couldn't be accessed on external media.
  154.      * @hide
  155.      */
  156.     public static final int INSTALL_FAILED_CONTAINER_ERROR = -18;

  157.     /**
  158.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  159.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  160.      * the new package couldn't be installed in the specified install
  161.      * location.
  162.      * @hide
  163.      */
  164.     public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19;

  165.     /**
  166.      * Installation return code: this is passed to the {@link IPackageInstallObserver} by
  167.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
  168.      * the new package couldn't be installed in the specified install
  169.      * location because the media is not available.
  170.      * @hide
  171.      */
  172.     public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE = -20;

  173.     /**
  174.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  175.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  176.      * if the parser was given a path that is not a file, or does not end with the expected
  177.      * '.apk' extension.
  178.      * @hide
  179.      */
  180.     public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;

  181.     /**
  182.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  183.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  184.      * if the parser was unable to retrieve the AndroidManifest.xml file.
  185.      * @hide
  186.      */
  187.     public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;

  188.     /**
  189.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  190.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  191.      * if the parser encountered an unexpected exception.
  192.      * @hide
  193.      */
  194.     public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;

  195.     /**
  196.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  197.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  198.      * if the parser did not find any certificates in the .apk.
  199.      * @hide
  200.      */
  201.     public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;

  202.     /**
  203.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  204.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  205.      * if the parser found inconsistent certificates on the files in the .apk.
  206.      * @hide
  207.      */
  208.     public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;

  209.     /**
  210.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  211.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  212.      * if the parser encountered a CertificateEncodingException in one of the
  213.      * files in the .apk.
  214.      * @hide
  215.      */
  216.     public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;

  217.     /**
  218.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  219.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  220.      * if the parser encountered a bad or missing package name in the manifest.
  221.      * @hide
  222.      */
  223.     public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;

  224.     /**
  225.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  226.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  227.      * if the parser encountered a bad shared user id name in the manifest.
  228.      * @hide
  229.      */
  230.     public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;

  231.     /**
  232.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  233.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  234.      * if the parser encountered some structural problem in the manifest.
  235.      * @hide
  236.      */
  237.     public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;

  238.     /**
  239.      * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
  240.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  241.      * if the parser did not find any actionable tags (instrumentation or application)
  242.      * in the manifest.
  243.      * @hide
  244.      */
  245.     public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;

  246.     /**
  247.      * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
  248.      * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
  249.      * if the system failed to install the package because of system issues.
  250.      * @hide
  251.      */
  252.     public static final int INSTALL_FAILED_INTERNAL_ERROR = -110;

  253.         private PackageInstallObserver installobserver;
  254.         private PackageDeleteObserver uninstallobserver;
  255.         private PackageManager pm;
  256.         private Method installmethod;
  257.         private Method uninstallmethod;
  258.        
  259.         private OnInstalledPackaged onInstalledPackaged;
  260.         private OnDeletedPackaged onDeletedPackaged;
  261.        
  262.     class PackageInstallObserver extends IPackageInstallObserver.Stub {

  263.             @Override
  264.                 public void packageInstalled(String packageName, int returnCode) throws RemoteException {
  265.                         if (onInstalledPackaged != null) {
  266.                                 onInstalledPackaged.packageInstalled(packageName, returnCode);
  267.                         }
  268.                 }
  269.         }
  270.    
  271.     class PackageDeleteObserver extends IPackageDeleteObserver.Stub {

  272.                 @Override
  273.                 public void packageDeleted(String packageName, int returnCode, String msg) throws RemoteException {
  274.                         if (onDeletedPackaged != null) {
  275.                                 onDeletedPackaged.packageDeleted(packageName, returnCode, msg);
  276.                         }       
  277.                 }
  278.     }
  279.        
  280.         public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {
  281.                
  282.         installobserver = new PackageInstallObserver();
  283.         uninstallobserver = new PackageDeleteObserver();
  284.         pm = context.getPackageManager();
  285.         
  286.         Class<?>[] installtypes = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
  287.         Class<?>[] uninstalltypes = new Class[] {String.class, IPackageDeleteObserver.class, int.class};
  288.                 installmethod = pm.getClass().getMethod("installPackage", installtypes);
  289.                 uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes);
  290.         }
  291.        
  292.         public void setOnInstalledPackaged(OnInstalledPackaged onInstalledPackaged) {
  293.                 this.onInstalledPackaged = onInstalledPackaged;
  294.         }

  295.         public void installPackage(String apkFile) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  296.                 installPackage(new File(apkFile));
  297.         }
  298.        
  299.         public void installPackage(File apkFile) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  300.                 if (!apkFile.exists()) throw new IllegalArgumentException();
  301.                 Uri packageURI = Uri.fromFile(apkFile);
  302.                 installPackage(packageURI);
  303.         }
  304.        
  305.         public void installPackage(Uri apkFile) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  306.                 installmethod.invoke(pm, new Object[] {apkFile, installobserver, INSTALL_REPLACE_EXISTING, null});
  307.         }
  308.        
  309.         public void uninstallPackage(String packageName) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  310.                 uninstallmethod.invoke(pm, new Object[] {packageName, uninstallobserver, 0});
  311.         }
  312.        
  313. }
复制代码
  1. package com.paulononaka.apihelper;

  2. public interface OnDeletedPackaged {
  3.        
  4.         public void packageDeleted(String packageName, int returnCode, String msg);

  5. }
复制代码
  1. package com.paulononaka.apihelper;

  2. public interface OnInstalledPackaged {
  3.        
  4.         public void packageInstalled(String packageName, int returnCode);

  5. }
复制代码
androidmanifest.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.       package="com.paulononaka"
  4.       android:versionCode="1"
  5.       android:versionName="1.0"
  6.       android:sharedUserId="android.uid.system">
  7.       
  8.     <uses-sdk android:minSdkVersion="8" />

  9.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  10.         <activity android:name=".InstallInBackgroundSample"
  11.                   android:label="@string/app_name">
  12.             <intent-filter>
  13.                 <action android:name="android.intent.action.MAIN" />
  14.                 <category android:name="android.intent.category.LAUNCHER" />
  15.             </intent-filter>
  16.         </activity>

  17.     </application>
  18.    
  19.     <uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
  20. </manifest>
复制代码
这里利用反射机制访问隐藏api,原本卸载的过程是,通过intent跳转到系统卸载activity中,经过用户确认才可以卸载,而直接在apk中执行系统activity的操作需要系统权限,
因此需要root过或者用特定android系统签名过,才可以当作系统app安装。root法比较通用,而签名法,由于大多数手机厂商都会修改android因此签名文件都不是原生android的,签名文件本身不会给你,因此只能在模拟器里耍耍,在自己手机里大部分是玩不转的。
签名命令:java -jar signapk.jar platform.x509.pem  platform.pk8  input.apk output.apk
signapk.jar可以在android改之理这个软件中获取
platform.x509.pem  platform.pk8  这2各是签名文件,在android源码目录\build\target\product\security\中可以找到

另附android源码下载大法——windows:
(需要python,需要代理或翻墙)
①安装git                http://rj.baidu.com/soft/detail/30195.html?ald                               
②安装tortoisegit        http://www.baidu.com/link?url=87 ... 5f60000000356739d84
③(设置代理啥的就不说了)git clone https://android.googlesource.com/platform/manifest.git   得到manifest文件夹
④manifest文件夹中,右键git bash here,命令git tag得到分支:
lichao26@B00000039559AB MINGW64 /e/1/manifest1/manifest (master)
$ git tag
adt_23.0.3
android-1.6_r1.1_
android-1.6_r1.2_
android-1.6_r1.3_
android-1.6_r1.4_
android-1.6_r1.5_
android-1.6_r1_
android-1.6_r2_
android-2.0.1_r1_
android-2.0_r1_
android-2.1_r1_
android-2.1_r2.1p2_
android-2.1_r2.1p_
android-2.1_r2.1s_
android-2.1_r2_
android-2.2.1_r1_
android-2.2.1_r2_
android-2.2.2_r1_
android-2.2.3_r1
android-2.2.3_r2
android-2.2.3_r2.1
android-2.2_r1.1_
android-2.2_r1.2_
android-2.2_r1.3_
android-2.2_r1_
android-2.3.1_r1_
android-2.3.2_r1_
android-2.3.3_r1.1_
android-2.3.3_r1_
android-2.3.4_r0.9_
android-2.3.4_r1_
android-2.3.5_r1_
android-2.3.6_r0.9
android-2.3.6_r1
android-2.3.7_r1
android-2.3_r1_
android-4.0.1_r1
android-4.0.1_r1.1
android-4.0.1_r1.2
android-4.0.2_r1
android-4.0.3_r1
android-4.0.3_r1.1
android-4.0.4_r1
android-4.0.4_r1.1
android-4.0.4_r1.2
android-4.0.4_r2
android-4.0.4_r2.1
android-4.1.1_r1
android-4.1.1_r1.1
android-4.1.1_r1_
android-4.1.1_r2
android-4.1.1_r3
android-4.1.1_r4
android-4.1.1_r5
android-4.1.1_r6
android-4.1.1_r6.1
android-4.1.2_r1
android-4.1.2_r2
android-4.1.2_r2.1
android-4.2.1_r1.1
android-4.2.1_r1.2
android-4.2.1_r1__
android-4.2.2_r1.1
android-4.2.2_r1.2
android-4.2.2_r1_
android-4.2_r1___
android-4.3.1_r1
android-4.3_r0.9
android-4.3_r0.9.1
android-4.3_r0.9.1_
android-4.3_r0.9_
android-4.3_r1
android-4.3_r1.1
android-4.3_r1_
android-4.3_r2
android-4.3_r2.1_
android-4.3_r2.1__
android-4.3_r2.2
android-4.3_r2.3
android-4.3_r2_
android-4.3_r3
android-4.3_r3.1
android-4.4.1_r1
android-4.4.1_r1.0.1
android-4.4.2_r1
android-4.4.2_r1.0.1
android-4.4.2_r2
android-4.4.2_r2.0.1
android-4.4.3_r1
android-4.4.3_r1.0.1
android-4.4.3_r1.1
android-4.4.3_r1.1.0.1
android-4.4.4_r1
android-4.4.4_r1.0.1
android-4.4.4_r2
android-4.4.4_r2.0.1
android-4.4_r1
android-4.4_r1.0.1
android-4.4_r1.1
android-4.4_r1.1.0.1
android-4.4_r1.2
android-4.4_r1.2.0.1
android-4.4w_r1
android-5.0.0_r1
android-5.0.0_r1.0.1
android-5.0.0_r2
android-5.0.0_r2.0.1
android-5.0.0_r3
android-5.0.0_r3.0.1
android-5.0.0_r4
android-5.0.0_r4.0.1
android-5.0.0_r5
android-5.0.0_r5.0.1
android-5.0.0_r5.1
android-5.0.0_r5.1.0.1
android-5.0.0_r6
android-5.0.0_r6.0.1
android-5.0.0_r7
android-5.0.0_r7.0.1
android-5.0.1_r1
android-5.0.2_r1
android-5.0.2_r3
android-5.1.0_r1
android-5.1.0_r3
android-5.1.0_r4
android-5.1.0_r5
android-5.1.1_r1
android-5.1.1_r10
android-5.1.1_r12
android-5.1.1_r13
android-5.1.1_r14
android-5.1.1_r15
android-5.1.1_r16
android-5.1.1_r17
android-5.1.1_r18
android-5.1.1_r19
android-5.1.1_r2
android-5.1.1_r20
android-5.1.1_r22
android-5.1.1_r23
android-5.1.1_r24
android-5.1.1_r25
android-5.1.1_r26
android-5.1.1_r28
android-5.1.1_r29
android-5.1.1_r3
android-5.1.1_r30
android-5.1.1_r4
android-5.1.1_r5
android-5.1.1_r6
android-5.1.1_r7
android-5.1.1_r8
android-5.1.1_r9
android-6.0.0_r1
android-6.0.0_r11
android-6.0.0_r12
android-6.0.0_r13
android-6.0.0_r2
android-6.0.0_r23
android-6.0.0_r24
android-6.0.0_r25
android-6.0.0_r26
android-6.0.0_r3
android-6.0.0_r4
android-6.0.0_r41
android-6.0.0_r5
android-6.0.0_r6
android-6.0.0_r7
android-6.0.1_r1
android-6.0.1_r3
android-cts-2.2_r8
android-cts-2.3_r10
android-cts-2.3_r11
android-cts-2.3_r12
android-cts-4.0.3_r1
android-cts-4.0.3_r2
android-cts-4.0_r1
android-cts-4.1_r1
android-cts-4.1_r2
android-cts-4.1_r4
android-cts-4.2_r2
android-cts-4.4_r1
android-cts-4.4_r4
android-cts-5.0_r2
android-cts-5.0_r3
android-cts-5.1_r1
android-cts-5.1_r2
android-cts-5.1_r3
android-cts-6.0_r1
android-cts-6.0_r2
android-cts-verifier-4.0.3_r1
android-cts-verifier-4.0_r1
android-l-preview_r2
android-m-preview
android-m-preview-1
android-m-preview-2
android-sdk-4.0.3-tools_r1
android-sdk-4.0.3_r1
android-sdk-4.4.2_r1
android-sdk-4.4.2_r1.0.1
android-sdk-adt_r16.0.1
android-sdk-adt_r20
android-sdk-support_r11
android-tsl-2.0
android-tsl-3.0
android-tsl-4.0
android-wear-5.0.0_r1
android-wear-5.1.0_r1
android-wear-5.1.1_r1
gradle_0.12.2
gradle_0.13.0
gradle_0.13.1
gradle_0.13.2
gradle_0.13.3
gradle_0.14.0
gradle_0.14.1
gradle_0.14.2
gradle_0.14.3
gradle_0.14.4
gradle_1.0.0
gradle_1.0.0-rc1
gradle_1.0.0-rc2
gradle_1.0.0-rc3
gradle_1.0.0-rc4
gradle_1.0.1
gradle_1.1.0
gradle_1.1.0-rc1
gradle_1.1.0-rc2
gradle_1.1.0-rc3
gradle_1.1.1
gradle_1.1.2
gradle_1.1.3
gradle_1.2.0
gradle_1.2.0-beta1
gradle_1.2.0-rc1
gradle_1.2.1
gradle_1.2.2
gradle_1.2.3
gradle_1.3.0-beta1
gradle_1.3.0-beta2
gradle_1.3.0-beta3
gradle_1.3.0-beta4
gradle_1.3.1
studio-1.4
studio-1.5
studio_0.8.6
studio_1.0.0
studio_1.0.1
ub-jack-arzon-mr2
webview-m40_r1
webview-m40_r2
webview-m40_r3
webview-m40_r4
⑤输入git checkout 分支名,获取想要分支的配置信息default.xml
lichao26@B00000039559AB MINGW64 /e/1/manifest1/manifest (master)
$ git checkout android-1.6_r1.1_
Note: checking out 'android-1.6_r1.1_'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 93b16e4... Manufest for android-1.6_r1.1
⑥编写python脚本下载downloadsource.py
import xml.dom.minidom  
import os  
from subprocess import call  
  
#downloaded source path  
rootdir = "e:/android-4.4.4_r2.0.1"  
  
#git program path  
git = "C:/Program Files/Git/bin/git.exe"  
  
dom = xml.dom.minidom.parse("E:/1/manifest/default.xml")  
root = dom.documentElement  
  
prefix = git + " clone https://android.googlesource.com/"  
suffix = ".git"  
  
if not os.path.exists(rootdir):  
    os.mkdir(rootdir)  
  
for node in root.getElementsByTagName("project"):  
    os.chdir(rootdir)  
    d = node.getAttribute("path")  
    last = d.rfind("/")  
    if last != -1:  
        d = rootdir + "/" + d[:last]  
        if not os.path.exists(d):  
            os.makedirs(d)  
        os.chdir(d)  
    cmd = prefix + node.getAttribute("name") + suffix  
    call(cmd)  
按自己情况改写rootdir  git  和xml路径
按需要删减default.xmlo
运行downloadsource.py即可!

android6.0源码约40+G

查阅android源码的最佳方式:android studio  直接打开工程根目录即可
配置了提示的选项后,可以跳转和引用了   ctrl+左键
回复

使用道具 举报

发表于 2015-12-18 14:00:38 | 显示全部楼层
顶chao哥~
回复

使用道具 举报

发表于 2016-1-17 21:45:16 | 显示全部楼层
谢谢分享,来一个试试。。。
回复 赞! 靠!

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-12-22 14:49 , Processed in 0.036227 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表