feat: build apk from project(dir) support

This commit is contained in:
hyb1996
2018-01-24 17:29:25 +08:00
parent 316415343f
commit c93c27fcaa
22 changed files with 365 additions and 34 deletions

View File

@@ -65,6 +65,8 @@ public interface ScriptEngine<S extends ScriptSource> {
@Override
public synchronized void setTag(String key, Object value) {
if(value == null)
return;
mTags.put(key, value);
}

View File

@@ -0,0 +1,136 @@
package com.stardust.autojs.project;
import android.content.Context;
import android.support.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.stardust.pio.PFiles;
import com.stardust.pio.UncheckedIOException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by Stardust on 2018/1/24.
*/
public class ProjectConfig {
public static final String CONFIG_FILE_NAME = "project.json";
private static final Gson GSON = new Gson();
@SerializedName("name")
private String mName;
@SerializedName("versionName")
private String mVersionName;
@SerializedName("versionCode")
private int mVersionCode;
@SerializedName("packageName")
private String mPackageName;
@SerializedName("main")
private String mMainScriptFile;
@SerializedName("assets")
private List<String> mAssets = new ArrayList<>();
public static ProjectConfig fromJson(String json) {
if (json == null) {
return null;
}
return GSON.fromJson(json, ProjectConfig.class);
}
public static ProjectConfig fromAssets(Context context, String path) {
try {
return fromJson(PFiles.read(context.getAssets().open(path)));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static ProjectConfig fromFile(String path) {
try {
return fromJson(PFiles.read(path));
} catch (UncheckedIOException e) {
e.printStackTrace();
return null;
}
}
public static ProjectConfig fromProjectDir(String path) {
return fromFile(configFileOfDir(path));
}
public static String configFileOfDir(String projectDir) {
return PFiles.join(projectDir, CONFIG_FILE_NAME);
}
public String getName() {
return mName;
}
public ProjectConfig setName(String name) {
mName = name;
return this;
}
public String getVersionName() {
return mVersionName;
}
public ProjectConfig setVersionName(String versionName) {
mVersionName = versionName;
return this;
}
public int getVersionCode() {
return mVersionCode;
}
public ProjectConfig setVersionCode(int versionCode) {
mVersionCode = versionCode;
return this;
}
public String getPackageName() {
return mPackageName;
}
public ProjectConfig setPackageName(String packageName) {
mPackageName = packageName;
return this;
}
public String getMainScriptFile() {
return mMainScriptFile;
}
public ProjectConfig setMainScriptFile(String mainScriptFile) {
mMainScriptFile = mainScriptFile;
return this;
}
public List<String> getAssets() {
return mAssets;
}
public void setAssets(List<String> assets) {
mAssets = assets;
}
public String toJson() {
return GSON.toJson(this);
}
}