| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Go Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style | |
| 3 // license that can be found in the LICENSE file. | |
| 4 | |
| 5 package main | |
| 6 | |
| 7 import ( | |
| 8 "encoding/xml" | |
| 9 "errors" | |
| 10 "fmt" | |
| 11 "html/template" | |
| 12 ) | |
| 13 | |
| 14 type manifestXML struct { | |
| 15 Activity activityXML `xml:"application>activity"` | |
| 16 } | |
| 17 | |
| 18 type activityXML struct { | |
| 19 Name string `xml:"name,attr"` | |
| 20 MetaData []metaDataXML `xml:"meta-data"` | |
| 21 } | |
| 22 | |
| 23 type metaDataXML struct { | |
| 24 Name string `xml:"name,attr"` | |
| 25 Value string `xml:"value,attr"` | |
| 26 } | |
| 27 | |
| 28 // manifestLibName parses the AndroidManifest.xml and finds the library | |
| 29 // name of the NativeActivity. | |
| 30 func manifestLibName(data []byte) (string, error) { | |
| 31 manifest := new(manifestXML) | |
| 32 if err := xml.Unmarshal(data, manifest); err != nil { | |
| 33 return "", err | |
| 34 } | |
| 35 if manifest.Activity.Name != "android.app.NativeActivity" { | |
| 36 return "", fmt.Errorf("can only build an .apk for NativeActivity
, not %q", manifest.Activity.Name) | |
| 37 } | |
| 38 libName := "" | |
| 39 for _, md := range manifest.Activity.MetaData { | |
| 40 if md.Name == "android.app.lib_name" { | |
| 41 libName = md.Value | |
| 42 break | |
| 43 } | |
| 44 } | |
| 45 if libName == "" { | |
| 46 return "", errors.New("AndroidManifest.xml missing meta-data and
roid.app.lib_name") | |
| 47 } | |
| 48 return libName, nil | |
| 49 } | |
| 50 | |
| 51 type manifestTmplData struct { | |
| 52 JavaPkgPath string | |
| 53 Name string | |
| 54 LibName string | |
| 55 } | |
| 56 | |
| 57 var manifestTmpl = template.Must(template.New("manifest").Parse(` | |
| 58 <manifest | |
| 59 xmlns:android="http://schemas.android.com/apk/res/android" | |
| 60 package="{{.JavaPkgPath}}" | |
| 61 android:versionCode="1" | |
| 62 android:versionName="1.0"> | |
| 63 | |
| 64 <uses-sdk android:minSdkVersion="9" /> | |
| 65 <application android:label="{{.Name}}" android:hasCode="false" android:d
ebuggable="true"> | |
| 66 <activity android:name="android.app.NativeActivity" | |
| 67 android:label="{{.Name}}" | |
| 68 android:configChanges="orientation|keyboardHidden"> | |
| 69 <meta-data android:name="android.app.lib_name" android:value="{{
.LibName}}" /> | |
| 70 <intent-filter> | |
| 71 <action android:name="android.intent.action.MAIN" /> | |
| 72 <category android:name="android.intent.category.LAUNCHER
" /> | |
| 73 </intent-filter> | |
| 74 </activity> | |
| 75 </application> | |
| 76 </manifest>`)) | |
| OLD | NEW |