帖子

如何把apk编入到系统ROM中

[复制链接]

该用户从未签到

27633  楼主| jianhuang3@ifly 发表于 2015-9-9 17:52:51 1#
以讯飞语音SDK包中的SpeechDemo工程为例,演示如何将一个apk编入到Android系统ROM中。

1.搭建安卓源码编译环境
         
          需要Ubuntu + Android源码工程 + 各种所需工具,搭建方法自行百度;


2.将SpeechDemo拷贝到“Android源码工程主目录/packages/apps/”下;


3.在SpeechDemo目录下编写Android.mk文件,内容如下:


#
# Copyright (C) 2008 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.
#

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

#指定apk的名称
LOCAL_PACKAGE_NAME := SpeechDemo

#指定引用的jar包名称,可以随意命名,只要后面的jar文件名正确即可
LOCAL_STATIC_JAVA_LIBRARIES := Msc Sunflower android-support-v4

#指定引用的so库,可以随意命名,只要后面的so文件名正确即可
LOCAL_JNI_SHARED_LIBRARIES := libmsc

#是否进行混淆,obfuscation表示混淆,其他选项如full、disable等均不混淆
LOCAL_PROGUARD_ENABLED := obfuscation

#指定混淆文件,在proguard.flags中指明不需要混淆的类和方法
LOCAL_PROGUARD_FLAG_FILES := proguard.flags

include $(BUILD_PACKAGE)

##################################################  
include $(CLEAR_VARS)  

#指定jar包文件
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := Msc:libs/Msc.jar Sunflower:libs/Sunflower.jar android-support-v4:libs/android-support-v4.jar

#指定so库文件
LOCAL_PREBUILT_LIBS := libmsc:libs/armeabi/libmsc.so

include $(BUILD_MULTI_PREBUILT)

#编译apk
include $(call all-makefiles-under,$(LOCAL_PATH))



4.如果需要代码混淆,要在mk文件打开选项并且提供混淆文件(示例中为proguard.flag),在文件中指定不需要混淆的内容:


# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-dontwarn com.iflytek.speech.**

-keepattributes Signature

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep class com.iflytek.cloud.**{*;}
-keep class com.iflytek.msc.**{*;}
-keep class com.iflytek.speech.**{*;}




5.在Android源码工程主目录打开终端,以root登录,执行:


         source build/envsetup.sh
         lunch 并选择所需要的平台
         cd packages/apps/SpeechDemo
         mm


         编译完成之后,将生成 out/target/product/目标平台/system/app/SpeechDemo.apk

然后就可以将整个OS文件打包成img镜像,烧写到机器上去啦。

注意:待编译的apk工程layout目录下所有布局文件中的文本都要采用间接引用的方式,即android:text="@string/xxx"方式,而不能采用android:text="xxx"方式,否则编译过程中会报错。

SpeechDemo工程目录

SpeechDemo工程目录

评分

参与人数 1语点 +2 收起 理由
kaiyuanheshang + 2 赞一个!

查看全部评分

iflytek-小黑 发表于 2015-9-10 08:56:43
2#
哇,楼主棒棒哒,楼主真帅撒
使用道具 举报 回复
hakmin 发表于 2016-3-18 14:44:15
3#
请问我要用多个服务但讯飞多服务集成中不支持的比如 人脸识别和语音识别一起用 Msc.jar 和 so库名相同 这个要怎么解决呢?求指教。
使用道具 举报 回复
喜欢雨天的我 发表于 2016-11-11 08:51:28
4#
棒棒的。有帮助。
使用道具 举报 回复