Android Programming: Pushing the Limits -- Chapter 1: Fine-Tuning Your Development Environment

來源:互聯網
上載者:User

標籤:

ADB命令Application Exerciser MonkeyGradleProGuard代碼重用版本控制靜態程式碼分析代碼重構開發人員模式 ADB命令:

@、adb help:查看adb命令。

@、adb devices:列出所有串連的安卓裝置和模擬器。

@、adb push <local> <remote> 把電腦裡的檔案拷貝到裝置中。

adb push e:\test.xml /sdcard/files.ldb/

@、adb pull <remote> <local> 把裝置中的檔案拷貝到電腦裡

@、adb devices:可以查看串連裝置的序號(serial number)

@、adb {–s <serial number>} logcat

@、adb logcat <tag>:<priority>

舉例:

在自訂類中定義一個日誌標籤,如:

private static final String LOG_TAG = “MyActivity”;

然後在此自訂類中的代碼中使用此標籤記錄日誌,如:

Log.d(LOG_TAG, “adb logcat test”);

這樣就可以在命令列中使用MyActivity這個標籤進行日誌過濾,命令格式:

adb logcat MyActivity:* *:S

註:*:S不能少,*:S表示讓logcat不展示其它日誌(原文:*:S,which tells logcat to silence all messages.)。

@、使用adb命令,實現通過Wifi串連裝置。註:安卓裝置與電腦使用同一Wifi。

1、  首先使用USB串連裝置與電腦;

2、  在命令列中輸入以下命令

adb devices //確認下串連的裝置,可以看到序號。

adb tcpip 5555  //以TCP/IP模式重啟裝置的adb進程,並監聽5555連接埠(adb預設連接埠)

adb connect <IP>  //通知電腦的adb Service 串連 IP 位址,其中IP為裝置的IP。

adb devices //再次確認串連的裝置,此時可看到一個<IP>:5555 的裝置。

3、  這樣拔掉USB線後,依然可以使用此裝置進行調試。

4、  當重啟裝置,或者使用 adb usb 命令,裝置的adb進程又恢複USB模式。

 

@、adb shell 可以對裝置使用命令列操作,類似於在Linux上操作一樣。

@、adb shell am <options> 可以啟動裝置上的Service,Intent等。

@、adb shell pm <options> 可以對裝置中的功能,許可權進行查看、安裝等操作。

具體瞭解adb命令,可查看http://developer.android.com/tools/help/adb.html

 

Application Exerciser Monkey:

@、一個命令列工具,能夠通過產生偽隨機事件來類比使用者操作對應用進行stress test。

@、命令:adb shell monkey –p <package name> <event count>

@、通過Monkeyrunner進行regression testing。You can find the API for the Monkeyrunner at http://developer.android.com/tools/help/monkeyrunner_concepts.html#APIClasses

 

Gradle:

The user guide for the new Gradle build system can be found at

http://tools.android.com/tech-docs/new-build-system/user-guide

 

ProGuard:

@、一個整合在Android SDK的工具,在發布應用時,可用此工具打亂代碼(obfuscate your code),這樣可增加應用被反編譯的難度。使用方法:在build.gradle檔案中添加:

buildTypes {

release {

runProguard true

proguardFile getDefaultProguardFile(‘proguard-android.txt’)

}

}

@、可以最佳化代碼,去除無用的代碼,減小發布應用的大小。

 

代碼重用:

@、使用JAR包,一般用於引用第三方的代碼。使用方法:把JAR包拷貝到libs目錄下,然後再build.gradle檔案中添加:

dependencies{

         compile files(‘libs/XXX.jar’) // XXX為要引用的JAR包名稱。

}

@、使用library project,常用於一個工程裡的多個應用,服務端和用戶端等之間共用一些工具類,通用視圖等。使用方法,在工程中建立一個module,類型選擇Android Library;然後在其它模組的build.gradle檔案中添加:

dependencies{

         compile project(‘:libraries:XXX’) // XXX為建立的library project的名稱。

}

 

版本控制:

@、git:

1、  https://git-scm.com/

2、  Version Control with Git 一本介紹git的書。

@、建立自己的gitolite伺服器,這樣就可以遠端存取Git respositories。

You can find the documentation and download for gitolite at

http://gitolite.com/gitolite

An excellent quick installation guide can be found at

http://gitolite.com/gitolite/qi.html

@、使用現成的伺服器,比如GitHub http://github.com

@、代碼檢查工具Gerrit

You can find out more about Gerrit and download the server at

https://code.google.com/p/gerrit (新地址:https://www.gerritcodereview.com/)

 

靜態程式碼分析:

@、使用Android SDK內建的lint工具進行程式碼分析。使用方法:在Android Studio的project視圖中,右鍵 >> Analyze >> Inspect Code…

 

代碼重構:

@、通過Refactor功能,實現靜態變數提取,方法提取,方法簽名變化等功能。詳細資料請查看:http://www.jetbrains.com/idea/features/refactoring.html

 

開發人員模式:

@、Android 4.2及以後版本系統,開發人員菜單被隱藏,開啟方法:進入“關於手機” >> “版本號碼(Build Number)”點擊7次 >> 返回上一層,可看到開發人員菜單。

 

Android Programming: Pushing the Limits -- Chapter 1: Fine-Tuning Your Development Environment

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.