Android Studio工程模板

今天逛论坛,发现有人分享了一个Android Studio的jME3工程模板生成器,挺有意思。虽然比不上BootMonkey功能那么强大,但是贵在短小精悍。

原帖:Android Studio template project generator

运行这个小程序需要Java 8,因为它的界面是用JavaFX制作的。

UI

用法很简单,输入Project名、Package名之后,点击“Generate”就会在当前目录下创建一个Android Stuido的工程模板。在Android Studio中通过File -> New -> Import Project来导入这个工程即可。

Project

工程下包含appcoredesktop这3个模块。

  • app是Android项目用的,自动创建了一个MainActivity用来启动jME3游戏。
  • core是游戏的核心部分,自动创建了一个SimpleApplication的子类Game
  • desktop则创建了一个桌面启动器DesktopLauncher,用来在桌面模式下调试游戏。

比较爽的是在app模块的src/main/asserts目录下自动按照jME3推荐的方式创建好了资源目录,挺整齐的。

下面是整个项目的build脚本,可以看到他已经把jme3常用的组件写好了,开发时根据需要去选用即可。

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
	repositories {
		jcenter()
	}
	dependencies {
		classpath 'com.android.tools.build:gradle:2.3.1'

		// NOTE: Do not place your application dependencies here; they belong
		// in the individual module build.gradle files
	}
}

allprojects {
	repositories {
		jcenter()
		maven { url "http://dl.bintray.com/jmonkeyengine/org.jmonkeyengine" }
	}

	tasks.withType(JavaCompile) {
		sourceCompatibility = "1.7"
		targetCompatibility = "1.7"
	}
}

// All modules:
//    jme3-android-native
//    jme3-android
//    jme3-blender
//    jme3-bullet-native-android
//    jme3-bullet-native
//    jme3-bullet
//    jme3-core
//    jme3-desktop
//    jme3-effects
//    jme3-examples
//    jme3-ios
//    jme3-jbullet
//    jme3-jogg
//    jme3-jogl
//    jme3-lwjgl
//    jme3-lwjgl3
//    jme3-networking
//    jme3-niftygui
//    jme3-plugins
//    jme3-terrain

def jme3 = [v:'3.1.0-stable', g:'org.jmonkeyengine']

project(":core") {
	apply plugin: "java"
	sourceSets.main.java.srcDirs = ["src/"]
	dependencies {
		// Basic
		compile "${jme3.g}:jme3-core:${jme3.v}"

		// Optional
//        compile "${jme3.g}:jme3-effects:${jme3.v}"
//        compile "${jme3.g}:jme3-plugins:${jme3.v}"
//        compile "${jme3.g}:jme3-jogg:${jme3.v}"
//        compile "${jme3.g}:jme3-terrain:${jme3.v}"
//        compile "${jme3.g}:jme3-blender:${jme3.v}"
//        compile "${jme3.g}:jme3-bullet-native:${jme3.v}"
//        compile "${jme3.g}:jme3-networking:${jme3.v}"

		// Resources
//        compile "net.sf.sociaal:jME3-testdata:3.0.0.20130526"
	}
}

project(":desktop") {
	apply plugin: "java"
	sourceSets.main.java.srcDirs = ["src/"]
	dependencies {
		compile files("../app/src/main/assets")
		compile project(":core")
		compile "${jme3.g}:jme3-desktop:${jme3.v}"
		compile "${jme3.g}:jme3-lwjgl:${jme3.v}"
	}
}

project(":app") {
	apply plugin: "android"
	dependencies {
		compile project(":core")
		compile "${jme3.g}:jme3-android:${jme3.v}"
		compile "${jme3.g}:jme3-android-native:${jme3.v}"
//        compile "${jme3.g}:jme3-bullet-native-android:${jme3.v}"
	}
}

task clean(type: Delete) {
	delete rootProject.buildDir
}