Android上的程式設計主要有兩種,一種是使用Adroid SDK(Software Development Kit),用Java開發;一種是使用Android NDK(Native Development Kit),用C/C++開發,因為Android核心是基于Linux Kernel的,用C/C++是最便捷的方式但相對複雜。這裡針對的是Java開發的方式。
Adroid上的Java虛拟機Dalvik虛拟機和經典java運作模式大緻相同,但Dalvik虛拟機是為Adroid系統優化定制過的。
标準的Java開發流程中,編譯時用Java JDK(Java Development Kit)編譯Java源碼檔案到.class檔案即Java位元組碼檔案(多個.class檔案可以打包成.jar檔案,僅僅是打包),标準Java虛拟機中運作的是.class位元組碼。
而Adroid上的Java編譯流程中同樣需要先編譯到.class檔案,但還需要Android SDK中的dx工具将.class檔案轉換成.dex檔案(在Dalvik虛拟機中執行的是dex位元組碼),然後用Android SDK中的打包工具aapt将.dex檔案、資源檔案、manifest.xml打包成程式包.apk檔案,.apk檔案就是可以被釋出的最終程式。
Mobile移動平台開發中,有種所謂的Native Application原生程式,這是相對Web開發中的Hyrid Application而言的,前面所述的Android上的兩種程式設計方式都可以算作Android平台上的Native Application,iOS平台的Native開發使用Object-C開發、不過現在又要改用Swift語言。
因為移動平台越來越多樣複雜,是以前端/用戶端Web開發越來越複雜,但通過一個Native Container來提供一個各個平台功能的統一接口是一種趨勢,于是就有Hybrid Application模式。Web開發中的Hyrid Application,是指在用戶端,用客戶機(Android or iOS)上的浏覽器,比如iOS中的UIWebView、Android中的WebView作為運作載體,Hyrid Application本身用Html5、CSS、Javascript編寫,可用Cordova包裝成Native程式存取運作平台的功能、可以一套代碼多個移動平台運作,相比于每個平台一套Native Application的開發方式大大減少工作量,但缺點是性能較差,PhoneGap是Cordova的一個變種被Javascript庫ExtJS所使用。
https://en.wikipedia.org/wiki/Apache_Cordova#Design_and_rationale
Apache Cordova (formerly PhoneGap) is a mobile application development framework originally created by Nitobi. Adobe Systems purchased Nitobi in 2011, rebranded it as PhoneGap, and later released an open source version of the software called Apache Cordova.software programmers to build applications for mobile devices using CSS3, HTML5, and JavaScript instead of relying on platform-specific APIs like those in Android, iOS, or Windows Phone.CSS3 and HTML5 for their rendering and JavaScript for their logic. HTML5 provides access to underlying hardware such as the accelerometer, camera, and GPS. However, browsers‘ support for HTML5-based device access is not consistent across mobile browsers, particularly older versions of Android. To overcome these limitations, Apache Cordova embeds the HTML5 code inside a native WebView on the device, using a foreign function interface to access the native resources of it.
Apache Cordova can be extended with native plug-ins, allowing developers to add more functionalities that can be called from JavaScript, making it communicate directly between the native layer and the HTML5 page. These plugins allow access to the device‘s accelerometer, camera, compass, file system, microphone, and more.
However, the use of Web-based technologies leads some Apache Cordova applications to run slower than native applications with similar functionality.Adobe Systems warns that applications may be rejected by Apple for being too slow or not feeling "native" enough (having appearance and functionality consistent with what users have come to expect on the platform). This can be an issue for some Apache Cordova applications.
React前端庫的Native功能與Cordova類似,也是提供一個運作平台與應用app之間的功能緩沖層。
https://facebook.github.io/react-native/
1. APKTool
反編譯android上的app檔案apk到smali代碼。apktool反編譯.apk檔案後會有個smali目錄和目錄中.smali結尾的檔案。
apktool的installation guid:https://ibotpeaches.github.io/Apktool/install/
smali和dex很容易混淆,因為dalvik虛拟機運作的是dex位元組碼,從.apk檔案加載到dalvik虛拟機再運作的流程中,是沒有smali代碼存在的位置的,而.smali檔案和.dex檔案可以互相轉換,之是以如此,是因為.dex位元組碼是不容易閱讀的,而轉換成smali文法的代碼則容易閱讀的多,也容易修改,修改完.smali後可以再轉換成.dex位元組碼,再用aapt工具重新打包、再重新簽名,那麼一個經過纂改的.apk檔案就完工了,但是前提是得有原先.apk檔案的簽名密鑰,不過對于有些廠商來說,他們的.apk檔案的簽名密鑰可以買到。。。
https://www.quora.com/What-is-smali-in-Android
Smali/Baksmali is an assembler/disassembler for the dex format used by dalvik, Android‘s Java VM implementation. The names "Smali" and "Baksmali" are the Icelandic冰島語 equivalents of "assembler" and "disassembler" respectively.
When you create an application code, the apk file contains a .dex file, which contains binary Dalvik bytecode. This is the format that the platform actually understands. However, it‘s not easy to read or modify binary code, so there are tools out there to convert to and from a human readable representation. The most common human readable format is known as Smali.
But the platform doesn‘t know anything about smali, it‘s just a tool to make it easier to work with the bytecode.
2. Signapk.jar
signapk.jar是android sdk自帶的工具,用Android自帶的signapk.jar + .x509.pem + .pk8簽名應用程式。這是一年多前寫的總結,現在找不到了目錄了,暈,得重新找。
3. dex2jar
可以将.dex檔案反編譯成.jar檔案,然後.jar檔案就可以用jd-jui檢視,jd-jui本身可以檢視标準java編譯成的.jar檔案。
https://github.com/pxb1988/dex2jar
4. jd-jui
jd-jui本身可以檢視标準java編譯成的.jar檔案。
http://jd.benow.ca/
5. apkpure.com
是不是煩透了android上的應用程式下載下傳安裝都得經過應用商店,那就試試在apkpure.com上查找下載下傳,我自己親自驗證過,apkpure.com可以安全下載下傳apk檔案,apk都是經過校驗的,沒有被替換過,因為我用apk作者或廠商的公開的簽名密鑰對apkpure.com上下載下傳的apk校驗過,是無誤的。
不過缺點是,程式自動更新一般得經過應用商店,apkpure.com上下載下傳的apk安裝後更新可能要自己手動。