在出游戏包的时候,如果需要接入sdk,一般都不会直接在unity里操作,而是导出android工程,在android工程里操作,从unity5.3开始已经支持导出android studio工程,相比eclipse有非常明显的有点,这里不再累述。
此篇主要教大家怎么导出android studio工程。
配置BuildSetting,选择android平台点击switch platform,如果工程较大,时间会比较长。
Build Syatem 选择Gradle,否则导出的是eclipse工程
Explort Project 选中,否则打出来就是apk
选择Player Settings,修改Bundle Identifier(包名),否则无法导出
点击export进行导出就可以了,没有android环境的需要先配置android环境。这个自行百度。
导出后的工程目录如下
打开android studio 选择打开一个现有的项目打开导出的工程
导入后工程如果没有报错,就可以使用了,修改代码之后可以直接Build APK进行打包,生成的包体在build\outputs\apk路径下
如果需要在编译器下执行或者做自动打包机,可以在editor下直接导出android工程,代码如下。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ExportProject {
//If you want to return an error from the commandline process
//you can either throw an exception which will cause Unity to exit with 1
//or else call EditorApplication.Exit with a non-zero code.
//If you want to pass parameters you can add them to the command line
//and retrieve them inside the method using System.Environment.GetCommandLineArgs.
[MenuItem("自动打包/1.Android / ExportAndroidProject")]