2
0
mirror of synced 2025-02-23 14:58:12 +00:00

cmd/gomobile: synthesize minSdkVersion for manifest

Fixes golang/go#13172

Change-Id: I16cab3f74f668ce3522a1a14c979aca5c988347c
Reviewed-on: https://go-review.googlesource.com/16843
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Daniel Skinner 2015-11-11 23:11:29 -06:00 committed by David Crawshaw
parent a54776c08a
commit 3b97f7024e
8 changed files with 39 additions and 11 deletions

View File

@ -10,7 +10,7 @@ license that can be found in the LICENSE file.
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<uses-sdk android:minSdkVersion="15" />
<!-- to talk to the host -->
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="testapp" android:debuggable="true">

View File

@ -141,7 +141,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 'android-19'
buildToolsVersion '21.1.2'
defaultConfig { minSdkVersion 14 }
defaultConfig { minSdkVersion 15 }
}
repositories {

View File

@ -86,6 +86,35 @@ func binaryXML(r io.Reader) ([]byte, error) {
}
switch tok := tok.(type) {
case xml.StartElement:
// uses-sdk is synthesized by the writer, disallow declaration in manifest.
if tok.Name.Local == "uses-sdk" {
return nil, fmt.Errorf("unsupported manifest tag <uses-sdk .../>")
} else if tok.Name.Local == "application" {
// synthesize <uses-sdk/> before handling <application> token
attr := xml.Attr{
Name: xml.Name{
Space: "http://schemas.android.com/apk/res/android",
Local: "minSdkVersion",
},
Value: "15",
}
ba, err := pool.getAttr(attr)
if err != nil {
return nil, fmt.Errorf("failed to synthesize attr minSdkVersion=\"15\"")
}
elements = append(elements,
&binStartElement{
line: line - 1, // current testing strategy is not friendly to synthesized tags, -1 for would-be location
ns: pool.getNS(""),
name: pool.get("uses-sdk"),
attr: []*binAttr{ba},
},
&binEndElement{
line: line - 1,
ns: pool.getNS(""),
name: pool.get("uses-sdk"),
})
}
// Intercept namespace definitions.
var attr []*binAttr
for _, a := range tok.Attr {

View File

@ -8,6 +8,7 @@ import (
"archive/zip"
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
@ -27,7 +28,7 @@ func TestBinaryXML(t *testing.T) {
sortPool, sortAttr = sortToMatchTest, sortAttrToMatchTest
defer func() { sortPool, sortAttr = origSortPool, origSortAttr }()
bin, err := binaryXML(bytes.NewBufferString(input))
bin, err := binaryXML(bytes.NewBufferString(fmt.Sprintf(input, "")))
if err != nil {
t.Fatal(err)
}
@ -77,7 +78,8 @@ func TestBinaryXML(t *testing.T) {
}
manifest := filepath.Join(tmpdir, "AndroidManifest.xml")
if err := ioutil.WriteFile(manifest, []byte(input), 0755); err != nil {
inp := fmt.Sprintf(input, "<uses-sdk android:minSdkVersion=\"15\" />")
if err := ioutil.WriteFile(manifest, []byte(inp), 0755); err != nil {
t.Fatal(err)
}
@ -807,7 +809,7 @@ license that can be found in the LICENSE file.
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
%s
<application android:label="Balloon世界" android:hasCode="false" android:debuggable="true">
<activity android:name="android.app.NativeActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

View File

@ -241,7 +241,7 @@ func buildAAR(androidDir string, pkg *build.Package) (err error) {
const (
javacTargetVer = "1.7"
minAndroidAPI = 9
minAndroidAPI = 15
)
func buildJar(w io.Writer, srcDir string) error {

View File

@ -61,7 +61,6 @@ var manifestTmpl = template.Must(template.New("manifest").Parse(`
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<application android:label="{{.Name}}" android:debuggable="true">
<activity android:name="org.golang.app.GoNativeActivity"
android:label="{{.Name}}"

View File

@ -98,7 +98,7 @@ N: android=http://schemas.android.com/apk/res/android
A: android:versionCode(0x0101021b)=(type 0x10)0x1
A: android:versionName(0x0101021c)="1.0" (Raw: "1.0")
E: uses-sdk (line=8)
A: android:minSdkVersion(0x0101020c)=(type 0x10)0x9
A: android:minSdkVersion(0x0101020c)=(type 0x10)0xf
E: application (line=9)
A: android:label(0x01010001)="FakeApp" (Raw: "FakeApp")
A: android:hasCode(0x0101000c)=(type 0x12)0x0
@ -121,7 +121,7 @@ const androidManifest = `
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<application android:label="FakeApp" android:hasCode="false" android:debuggable="true">
<activity android:name="android.app.NativeActivity"
android:label="FakeApp"

View File

@ -10,8 +10,6 @@ license that can be found in the LICENSE file.
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<!-- In order to access the network, your application manifest must
specify the permission requirement. See the following page for
details.