android 中如何将多个相互关联的APK打包成一个APK?
来源:互联网 发布:淘宝每日好店怎么上 编辑:程序博客网 时间:2024/06/17 03:01
在项目中经常遇到这种问题,为了提高效率,实现资源利用最大化,往往把一个项目不同功能模块化,每个模块由相应的人员各自构建工程,最后进行整合。比如一个工程项目有多个模块A,B,C,每个模块各自有自己的APK生成,其中A的APK需要调用B,C的APK,那么最后整合的时候我们的问题就来了,如何才能把这多个APK打包成一个APK呢?
我们举例说明:
假如有两个APK:FatherApp,SonApp,其中,FatherApp主页面只有一个按钮,用来调用SonApp的一个页面,最后,两个APP要合并为一个APK文件递交给客户。
FatherApp 代码如下:
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Button android:id="@+id/sonBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="My son APP" /></RelativeLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.fatherproject" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.fatherproject.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
MainActivity.java
package com.example.fatherproject;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.widget.Button;public class MainActivity extends Activity {private Button btn = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn = (Button)findViewById(R.id.sonBtn);btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubintentToSunActivity();}});} private void intentToSunActivity() { String action = "com.mytest"; //用于调用SonApp Uri uri = Uri.parse("file:"+"//123456"); Intent intent = new Intent(action,uri); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); }@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}
SonApp 代码如下:
添加一个新的Activity:SonActivity.java,其他均为默认
package com.example.sunapp;import android.app.Activity;import android.os.Bundle;import android.view.Menu;public class SonActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}
修改AndroidMainfest.xml,实现SonActivity可以被FatherApp调用:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sunapp" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.sunapp.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.sunapp.SonActivity" android:exported="true" android:screenOrientation="portrait"> <intent-filter> <action android:name="com.mytest" /> <data android:scheme="file"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application></manifest>
以上代码就是两个相互调用的APK,接下来我们给出合并的过程:
1,点击SunApp—右键—Export—Java—JAR file—next—按下图勾选,同时填写路径,到最后finish会生成一个SunApp.jar
2,点击SunApp—右键—Properties—Android,选中Is Library---Apply
3,点击FatherApp—右键—Properties—Android,取消选中Is Library---Add—SonApp:
这里有个笔误,我就不该了,看出来的别介意呵呵,这样就成功把SonApp引用到FatherApp中了
4,在FeatherApp的mainfest.xml中添加:
<activity
android:name=".com.example.sunapp"android:label="@string/app_name"/>
这样就可以了,最后奉上代码demo连接:点击打开链接 免费下载,共勉!
- android 中如何将多个相互关联的APK打包成一个APK?
- 如何把多个Android Project打包成一个APK
- 如何把多个Android Project打包成一个APK
- Android 开发中,如何将多个程序打包成一个apk文件,但是安装完成后显示多个程序?
- android是如何打包apk的
- 如何使用ionic打包Android的apk
- 如何将android项目打包成apk
- 如何将android项目打包成apk
- Android 打包成APK
- Android 打包成APK
- 两个apk打包成一个apk发布
- 转载将多个工程打包成一个apk
- Android中APK打包流程
- 如何把多个android project打包成一个apk(你的项目如何引用其他项目)
- Android Apk打包过程概述:Android是如何打包apk的
- Android:一个apk中调用另一个apk的activity
- android 源码 打包成apk的实现
- android 源码 打包成apk的实现
- R/BioC序列处理之一:Biostrings常量与序列容器
- R/BioC序列处理之二:Biostrings序列的基本操作
- R/BioC序列处理之三:Biostrings模式匹配和序列比对
- R/BioC序列处理之四:BSgenome简介
- Emacs月月积累(二):窗口、缓冲区和常用模式切换
- android 中如何将多个相互关联的APK打包成一个APK?
- R/BioC序列处理之五:Rle和Ranges
- Emacs月月积累(终结篇):熟练使用org-mode管理日常事务
- 在debian中安装Emacs和R/Bioconductor
- 在R中使用Primer3和NCBI-BLAST进行高通量引物设计
- ggplot2作图详解1:入门函数qplot
- ggplot2作图详解2:ggplot图形对象
- ggplot2作图详解3:映射(mapping)
- ggplot2作图详解4:分面(faceting)