cmd/gomobile: add arg to set android api level
Fixes golang/go#31905 Change-Id: Icee0ece2e78028fa4afd8b273b86e4eed404d99a Reviewed-on: https://go-review.googlesource.com/c/mobile/+/176077 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Родитель
12c8d8ccab
Коммит
ab05907dce
|
@ -148,7 +148,7 @@ func buildAAR(srcDir, androidDir string, pkgs []*build.Package, androidArchs []s
|
|||
}
|
||||
const manifestFmt = `<manifest xmlns:android="http://schemas.android.com/apk/res/android" package=%q>
|
||||
<uses-sdk android:minSdkVersion="%d"/></manifest>`
|
||||
fmt.Fprintf(w, manifestFmt, "go."+pkgs[0].Name+".gojni", minAndroidAPI)
|
||||
fmt.Fprintf(w, manifestFmt, "go."+pkgs[0].Name+".gojni", buildAndroidAPI)
|
||||
|
||||
w, err = aarwcreate("proguard.txt")
|
||||
if err != nil {
|
||||
|
@ -365,7 +365,7 @@ func androidAPIPath() (string, error) {
|
|||
defer sdkDir.Close()
|
||||
fis, err := sdkDir.Readdir(-1)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to find android SDK platform (min API level: %d): %v", minAndroidAPI, err)
|
||||
return "", fmt.Errorf("failed to find android SDK platform (API level: %d): %v", buildAndroidAPI, err)
|
||||
}
|
||||
|
||||
var apiPath string
|
||||
|
@ -376,7 +376,7 @@ func androidAPIPath() (string, error) {
|
|||
continue
|
||||
}
|
||||
n, err := strconv.Atoi(name[len("android-"):])
|
||||
if err != nil || n < minAndroidAPI {
|
||||
if err != nil || n < buildAndroidAPI {
|
||||
continue
|
||||
}
|
||||
p := filepath.Join(sdkDir.Name(), name)
|
||||
|
@ -387,8 +387,8 @@ func androidAPIPath() (string, error) {
|
|||
}
|
||||
}
|
||||
if apiVer == 0 {
|
||||
return "", fmt.Errorf("failed to find android SDK platform (min API level: %d) in %s",
|
||||
minAndroidAPI, sdkDir.Name())
|
||||
return "", fmt.Errorf("failed to find android SDK platform (API level: %d) in %s",
|
||||
buildAndroidAPI, sdkDir.Name())
|
||||
}
|
||||
return apiPath, nil
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ are copied into the output.
|
|||
Flag -iosversion sets the minimal version of the iOS SDK to compile against.
|
||||
The default version is 7.0.
|
||||
|
||||
Flag -androidapi sets the Android API version to compile against.
|
||||
The default and minimum is 15.
|
||||
|
||||
The -bundleid flag is required for -target ios and sets the bundle ID to use
|
||||
with the app.
|
||||
|
||||
|
@ -230,6 +233,7 @@ var (
|
|||
buildWork bool // -work
|
||||
buildBundleID string // -bundleid
|
||||
buildIOSVersion string // -iosversion
|
||||
buildAndroidAPI int // -androidapi
|
||||
)
|
||||
|
||||
func addBuildFlags(cmd *command) {
|
||||
|
@ -239,6 +243,7 @@ func addBuildFlags(cmd *command) {
|
|||
cmd.flag.StringVar(&buildTarget, "target", "android", "")
|
||||
cmd.flag.StringVar(&buildBundleID, "bundleid", "", "")
|
||||
cmd.flag.StringVar(&buildIOSVersion, "iosversion", "7.0", "")
|
||||
cmd.flag.IntVar(&buildAndroidAPI, "androidapi", minAndroidAPI, "")
|
||||
|
||||
cmd.flag.BoolVar(&buildA, "a", false, "")
|
||||
cmd.flag.BoolVar(&buildI, "i", false, "")
|
||||
|
|
|
@ -106,6 +106,9 @@ are copied into the output.
|
|||
Flag -iosversion sets the minimal version of the iOS SDK to compile against.
|
||||
The default version is 7.0.
|
||||
|
||||
Flag -androidapi sets the Android API version to compile against.
|
||||
The default and minimum is 15.
|
||||
|
||||
The -bundleid flag is required for -target ios and sets the bundle ID to use
|
||||
with the app.
|
||||
|
||||
|
|
|
@ -83,6 +83,9 @@ func envInit() (err error) {
|
|||
// Setup the cross-compiler environments.
|
||||
if ndkRoot, err := ndkRoot(); err == nil {
|
||||
androidEnv = make(map[string][]string)
|
||||
if buildAndroidAPI < minAndroidAPI {
|
||||
return fmt.Errorf("gomobile requires Android API level >= %d", minAndroidAPI)
|
||||
}
|
||||
for arch, toolchain := range ndk {
|
||||
clang := toolchain.Path(ndkRoot, "clang")
|
||||
clangpp := toolchain.Path(ndkRoot, "clang++")
|
||||
|
@ -283,15 +286,23 @@ func archNDK() string {
|
|||
type ndkToolchain struct {
|
||||
arch string
|
||||
abi string
|
||||
minAPI int
|
||||
toolPrefix string
|
||||
clangPrefix string
|
||||
}
|
||||
|
||||
func (tc *ndkToolchain) ClangPrefix() string {
|
||||
if buildAndroidAPI < tc.minAPI {
|
||||
return fmt.Sprintf("%s%d", tc.clangPrefix, tc.minAPI)
|
||||
}
|
||||
return fmt.Sprintf("%s%d", tc.clangPrefix, buildAndroidAPI)
|
||||
}
|
||||
|
||||
func (tc *ndkToolchain) Path(ndkRoot, toolName string) string {
|
||||
var pref string
|
||||
switch toolName {
|
||||
case "clang", "clang++":
|
||||
pref = tc.clangPrefix
|
||||
pref = tc.ClangPrefix()
|
||||
default:
|
||||
pref = tc.toolPrefix
|
||||
}
|
||||
|
@ -312,27 +323,31 @@ var ndk = ndkConfig{
|
|||
"arm": {
|
||||
arch: "arm",
|
||||
abi: "armeabi-v7a",
|
||||
minAPI: 16,
|
||||
toolPrefix: "arm-linux-androideabi",
|
||||
clangPrefix: "armv7a-linux-androideabi16",
|
||||
clangPrefix: "armv7a-linux-androideabi",
|
||||
},
|
||||
"arm64": {
|
||||
arch: "arm64",
|
||||
abi: "arm64-v8a",
|
||||
minAPI: 21,
|
||||
toolPrefix: "aarch64-linux-android",
|
||||
clangPrefix: "aarch64-linux-android21",
|
||||
clangPrefix: "aarch64-linux-android",
|
||||
},
|
||||
|
||||
"386": {
|
||||
arch: "x86",
|
||||
abi: "x86",
|
||||
minAPI: 16,
|
||||
toolPrefix: "i686-linux-android",
|
||||
clangPrefix: "i686-linux-android16",
|
||||
clangPrefix: "i686-linux-android",
|
||||
},
|
||||
"amd64": {
|
||||
arch: "x86_64",
|
||||
abi: "x86_64",
|
||||
minAPI: 21,
|
||||
toolPrefix: "x86_64-linux-android",
|
||||
clangPrefix: "x86_64-linux-android21",
|
||||
clangPrefix: "x86_64-linux-android",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@ func installOpenAL(gomobilepath string) error {
|
|||
cmd := exec.Command(cmake,
|
||||
initOpenAL,
|
||||
"-DCMAKE_TOOLCHAIN_FILE="+initOpenAL+"/XCompile-Android.txt",
|
||||
"-DHOST="+t.clangPrefix)
|
||||
"-DHOST="+t.ClangPrefix())
|
||||
cmd.Dir = buildDir
|
||||
tcPath := filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin")
|
||||
if !buildN {
|
||||
|
|
Загрузка…
Ссылка в новой задаче