---
title: "html5游戏移植到android并打包成apk，加广告《二》"
author: "喧嚣求静"
date: "2015-06-06T09:50:37Z"
tags: []
categories: ["移动开发"]
slug: "html5-android-apk"
draft: false
lastmod: "2015-06-06T10:17:21Z"
id: 2217484
url: "https://913.iteye.com/blog/2217484"
---

html5游戏移植到android并打包成apk，加广告《二》

在上篇简单介绍了[h5游戏使用腾讯X5内核SDK集成到android](/admin/blogs/2217482)

这篇则讲解开发集成，先看看工程目录结构

![](http://dl2.iteye.com/upload/attachment/0109/2680/64d165e2-94d9-385f-9268-12e99a272885.png)

 

qqbrowser\_sdk\_v1.2.jar为X5内核sdk,[下载注册开发者](http://x5.tencent.com/index)

BaseH5Activity是我自己封装好的基类

 

assets目录下为h5游戏源码

![](http://dl2.iteye.com/upload/attachment/0109/2682/892197b6-fa31-39d3-bce6-ef09bf9f3b59.png)

 

关于加载assets目录下为h5游戏,以fdgg为例

```
Intent flyI=new Intent(MainActivity.this,GameActivity.class);
      flyI.putExtra("assertPath","file:///android_asset/fdgg/index.html");
MainActivity.this.startActivity(flyI);
```

 

 

```
public class GameActivity extends BaseH5Activity {
	
	private String assertPath;
	private FrameLayout adContain;
	
	 Handler jsHandler= new Handler(); 
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gameview);
		
		assertPath=getIntent().getStringExtra("assertPath");
		if(assertPath!=null)
		   myWebView.loadUrl(assertPath);
		else
		   myWebView.loadUrl("file:///android_asset/xiongchumo/index.html");
		
		bindEvt();
		 adContain=(FrameLayout)findViewById(R.id.webId);
		 adContain.removeAllViews();
		 adContain.addView(myWebView);
		
		ActivityManagerUtlis.getInstance().addActivity(this);
	}
}
```

 

```
 myWebView.loadUrl("file:///android_asset/xiongchumo/index.html");
```

 最终是webview加载H5游戏，此处用X5 SDK中webview代替原生的，因为x5 sdk支持H5更好

好了，开发完成，里面的细节，就自己看源码吧

源码包括了我在工作设计的用于h5调用，性能调优代码，现放出源码

 

### [h5游戏集成源码](http://pan.baidu.com/s/1pJ3e1jd)

## [h5游戏集成apk演示](http://pan.baidu.com/s/1kTqvxiR)