?
Android應用程式編譯成系統程序簡介
?
簡介:在android操作系統中,有一些應用程序,如打電話,系統設置、鬧鐘等等在我們購買手機的時候就已經有了,如果我們想寫一個應用程序到系統中,而又不給用戶刪除。該如何做?本文將提供一個簡單的例子,看看android系統里是如何把應用程序寫入系統中去的。
?
1、開發環境
?? ? 操作系統:Ubuntu xx
?? ? 開發工具:Eclipse
?? ? Android SDK:android 2.2
2、開發環境搭建過程
?? ?要想把android應用程序寫入系統中,首先要搭建一個android文件系統的開發環境。由于網上很多搭建環境的例子,這里只羅列要點二具體介紹。
?? ?(1)、下載Android文件系統源碼
?? ?http://source.android.com/source/download.html
?? ?(2)、Eclipse源碼開發環境
?? ?http://source.android.com/source/using-eclipse.html
?? ?(3)、Eclipse開發App環境
?? ?這個可以參考android sdk 的文檔或者網上查找資料
?
?
3、以Helloworld為例
?? ? (1)、建立一個App
在Eclipse-App開發環境中新建一個Android Project命名為Helloworld,然后在模擬器上調試運行。將會見到下看到Helloworld 程序運行,并在屏幕上顯示Hello world ,Main!這一步我們不需要寫任何的代碼。
?? ? (2)、移植App到Android
?? ? ? 在linux系統中進入Android的源碼目錄,來到 ./package/apps/Settings/ ?目錄,把這里的Android.mk復制到剛才那個HelloWorld App 的 跟目錄下,并修改Android.mk文件
?
Android.mk
?
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := Helloworld #與工程名字相同
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
?
?
?? ?(3)、修改/bulid/target/product/generic.mk 把工程編譯到系統中
?
?
generic.mk
?
#
# Copyright (C) 2007 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# ? ? ?http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
?
# This is a generic product that isn't specialized for a specific device.
# It includes the base Android platform.
?
PRODUCT_PACKAGES := \
?? ?AccountAndSyncSettings \
?? ?CarHome \
?? ?DeskClock \
?? ?AlarmProvider \
?? ?Bluetooth \
?? ?Calculator \
?? ?Calendar \
?? ?Camera \
?? ?CertInstaller \
?? ?DrmProvider \
?? ?Email \
?? ?Gallery3D \
?? ?LatinIME \
?? ?Launcher2 \
?? ?Mms \
?? ?Music \
?? ?Provision \
?? ?Protips \
?? ?QuickSearchBox \
?? ?Settings \
?? ?Sync \
?? ?Updater \
?? ?CalendarProvider \
?? ?SyncProvider? \
?? ??Helloworld
?
$(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)
?
# Overrides
PRODUCT_BRAND := generic
PRODUCT_DEVICE := generic
PRODUCT_NAME := generic
?
?? ?(4)、將Android工程拷貝到 ./package/apps/ 目錄下
?
此時,系統的代碼環境已經構建好。
?
?? ?(5)、編譯Android SDK?
?? ? 在Android源碼根目錄下執行: #make sdk
?
?? ? 等待......
?
?? ?編譯完成后
?
?? ?來到/out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86/tools/下,執行 :
?
?? ??./emulator -avd ANDROID2
?
?? ?啟動模擬器,就會開到Helloworld會在Android系統中。
?
?? ?通過 設置->應用程序->管理應用程序->全部-選擇->Helloworld ?(如下圖示我們可以看到該程序為一個系統 默認啟動 的程序,并且用戶不可以將其 卸載 )
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
