| 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 mainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ |
| 6 | |
| 7 | import ( |
| 8 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 9 | "crypto/x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/" |
| 10 | "encoding/base64scip-go gomod github.com/golang/go/src go1.24.0 `encoding/base64`/" |
| 11 | "encoding/pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/" |
| 12 | "encoding/xmlscip-go gomod github.com/golang/go/src go1.24.0 `encoding/xml`/" |
| 13 | "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/" |
| 14 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 15 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 16 | "logscip-go gomod github.com/golang/go/src go1.24.0 log/" |
| 17 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 18 | "pathscip-go gomod github.com/golang/go/src go1.24.0 path/" |
| 19 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 20 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 21 | |
| 22 | "golang.org/x/mobile/internal/binresscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/" |
| 23 | "golang.org/x/tools/go/packagesscip-go gomod golang.org/x/tools v0.41.0 `golang.org/x/tools/go/packages`/" |
| 24 | ) |
| 25 | |
| 26 | func goAndroidBuildscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/goAndroidBuild().(pkg *packagesscip-go gomod golang.org/x/tools v0.41.0 `golang.org/x/tools/go/packages`/.Packagescip-go gomod golang.org/x/tools v0.41.0 `golang.org/x/tools/go/packages`/Package#, targets []targetInfoscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/targetInfo#) (map[string]bool, error) { |
| 27 | ndkRoot, err := ndkRootscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndkRoot().(targets...) |
| 28 | if err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | appName := pathscip-go gomod github.com/golang/go/src go1.24.0 path/.Basescip-go gomod github.com/golang/go/src go1.24.0 path/Base().(pkg.PkgPathscip-go gomod golang.org/x/tools v0.41.0 `golang.org/x/tools/go/packages`/Package#PkgPath.) |
| 32 | libName := androidPkgNamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/androidPkgName().(appName) |
| 33 | |
| 34 | // TODO(hajimehoshi): This works only with Go tools that assume all source files are in one directory. |
| 35 | // Fix this to work with other Go tools. |
| 36 | dir := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Dir().(pkg.GoFilesscip-go gomod golang.org/x/tools v0.41.0 `golang.org/x/tools/go/packages`/Package#GoFiles.[0]) |
| 37 | |
| 38 | manifestPath := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(dir, "AndroidManifest.xml") |
| 39 | manifestData, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.24.0 os/ReadFile().(manifestPath) |
| 40 | if err != nil { |
| 41 | if !osscip-go gomod github.com/golang/go/src go1.24.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.24.0 os/IsNotExist().(err) { |
| 42 | return nil, err |
| 43 | } |
| 44 | |
| 45 | buf := new(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#) |
| 46 | buf.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#WriteString().(`<?xml version="1.0" encoding="utf-8"?>`) |
| 47 | err := manifestTmplscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/manifestTmpl..Executescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template#Execute().(buf, manifestTmplDatascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/manifestTmplData#{ |
| 48 | // TODO(crawshaw): a better package path. |
| 49 | JavaPkgPathscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/manifestTmplData#JavaPkgPath.: "org.golang.todo." + libName, |
| 50 | Namescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/manifestTmplData#Name.: stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Titlescip-go gomod github.com/golang/go/src go1.24.0 strings/Title().(appName), |
| 51 | LibNamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/manifestTmplData#LibName.: libName, |
| 52 | }) |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | manifestData = buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().() |
| 57 | if buildVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildV. { |
| 58 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr., "generated AndroidManifest.xml:\n%s\n", manifestData) |
| 59 | } |
| 60 | } else { |
| 61 | libName, err = manifestLibNamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/manifestLibName().(manifestData) |
| 62 | if err != nil { |
| 63 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("error parsing %s: %v", manifestPath, err) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | libFiles := []string{} |
| 68 | nmpkgs := make(map[string]map[string]bool) // map: arch -> extractPkgs' output |
| 69 | |
| 70 | for _, t := range targets { |
| 71 | toolchain := ndkscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndk..Toolchainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndkConfig#Toolchain().(t.archscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/targetInfo#arch.) |
| 72 | libPath := "lib/" + toolchain.abiscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndkToolchain#abi. + "/lib" + libName + ".so" |
| 73 | libAbsPath := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(tmpdirscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/tmpdir., libPath) |
| 74 | if err := mkdirscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/mkdir().(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Dir().(libAbsPath)); err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | err = goBuildscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/goBuild().( |
| 78 | pkg.PkgPathscip-go gomod golang.org/x/tools v0.41.0 `golang.org/x/tools/go/packages`/Package#PkgPath., |
| 79 | androidEnvscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/androidEnv.[t.archscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/targetInfo#arch.], |
| 80 | "-buildmode=c-shared", |
| 81 | "-o", libAbsPath, |
| 82 | ) |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | nmpkgs[t.archscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/targetInfo#arch.], err = extractPkgsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/extractPkgs().(toolchain.Pathscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndkToolchain#Path().(ndkRoot, "nm"), libAbsPath) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | libFiles = append(libFiles, libPath) |
| 91 | } |
| 92 | |
| 93 | block, _ := pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Decode().([]byte(debugCertscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/debugCert.)) |
| 94 | if block == nil { |
| 95 | return nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("no debug cert") |
| 96 | } |
| 97 | privKey, err := x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/.ParsePKCS1PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/ParsePKCS1PrivateKey().(block.Bytesscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Block#Bytes.) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | if buildOscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildO. == "" { |
| 103 | buildOscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildO. = androidPkgNamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/androidPkgName().(pathscip-go gomod github.com/golang/go/src go1.24.0 path/.Basescip-go gomod github.com/golang/go/src go1.24.0 path/Base().(pkg.PkgPathscip-go gomod golang.org/x/tools v0.41.0 `golang.org/x/tools/go/packages`/Package#PkgPath.)) + ".apk" |
| 104 | } |
| 105 | if !stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasSuffix().(buildOscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildO., ".apk") { |
| 106 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("output file name %q does not end in '.apk'", buildOscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildO.) |
| 107 | } |
| 108 | var out ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Writerscip-go gomod github.com/golang/go/src go1.24.0 io/Writer# |
| 109 | if !buildNscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildN. { |
| 110 | f, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Createscip-go gomod github.com/golang/go/src go1.24.0 os/Create().(buildOscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildO.) |
| 111 | if err != nil { |
| 112 | return nil, err |
| 113 | } |
| 114 | defer func() { |
| 115 | if cerr := f.Closescip-go gomod github.com/golang/go/src go1.24.0 os/File#Close().(); err == nil { |
| 116 | err = cerr |
| 117 | } |
| 118 | }() |
| 119 | out = f |
| 120 | } |
| 121 | |
| 122 | var apkw *Writerscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/Writer# |
| 123 | if !buildNscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildN. { |
| 124 | apkw = NewWriterscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/NewWriter().(out, privKey) |
| 125 | } |
| 126 | apkwCreate := func(name string) (ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Writerscip-go gomod github.com/golang/go/src go1.24.0 io/Writer#, error) { |
| 127 | if buildVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildV. { |
| 128 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr., "apk: %s\n", name) |
| 129 | } |
| 130 | if buildNscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildN. { |
| 131 | return ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Discardscip-go gomod github.com/golang/go/src go1.24.0 io/Discard., nil |
| 132 | } |
| 133 | return apkw.Createscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/Writer#Create().(name) |
| 134 | } |
| 135 | apkwWriteFile := func(dst, src string) error { |
| 136 | w, err := apkwCreate(dst) |
| 137 | if err != nil { |
| 138 | return err |
| 139 | } |
| 140 | if !buildNscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildN. { |
| 141 | f, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Openscip-go gomod github.com/golang/go/src go1.24.0 os/Open().(src) |
| 142 | if err != nil { |
| 143 | return err |
| 144 | } |
| 145 | defer f.Closescip-go gomod github.com/golang/go/src go1.24.0 os/File#Close().() |
| 146 | if _, err := ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Copyscip-go gomod github.com/golang/go/src go1.24.0 io/Copy().(w, f); err != nil { |
| 147 | return err |
| 148 | } |
| 149 | } |
| 150 | return nil |
| 151 | } |
| 152 | |
| 153 | w, err := apkwCreate("classes.dex") |
| 154 | if err != nil { |
| 155 | return nil, err |
| 156 | } |
| 157 | dexData, err := base64scip-go gomod github.com/golang/go/src go1.24.0 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.24.0 `encoding/base64`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.24.0 `encoding/base64`/Encoding#DecodeString().(dexStrscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/dexStr.) |
| 158 | if err != nil { |
| 159 | logscip-go gomod github.com/golang/go/src go1.24.0 log/.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 log/Fatalf().("internal error bad dexStr: %v", err) |
| 160 | } |
| 161 | if _, err := w.Writescip-go gomod github.com/golang/go/src go1.24.0 io/Writer#Write().(dexData); err != nil { |
| 162 | return nil, err |
| 163 | } |
| 164 | |
| 165 | for _, libFile := range libFiles { |
| 166 | if err := apkwWriteFile(libFile, filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(tmpdirscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/tmpdir., libFile)); err != nil { |
| 167 | return nil, err |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | for _, t := range targets { |
| 172 | toolchain := ndkscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndk..Toolchainscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndkConfig#Toolchain().(t.archscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/targetInfo#arch.) |
| 173 | if nmpkgs[t.archscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/targetInfo#arch.]["golang.org/x/mobile/exp/audio/al"] { |
| 174 | dst := "lib/" + toolchain.abiscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/ndkToolchain#abi. + "/libopenal.so" |
| 175 | src := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(gomobilepathscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/gomobilepath., dst) |
| 176 | if _, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Statscip-go gomod github.com/golang/go/src go1.24.0 os/Stat().(src); err != nil { |
| 177 | return nil, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("the Android requires the golang.org/x/mobile/exp/audio/al, but the OpenAL libraries was not found. Please run gomobile init with the -openal flag pointing to an OpenAL source directory.") |
| 178 | } |
| 179 | if err := apkwWriteFile(dst, src); err != nil { |
| 180 | return nil, err |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // Add any assets. |
| 186 | var arsc struct { |
| 187 | iconPath string |
| 188 | } |
| 189 | assetsDir := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(dir, "assets") |
| 190 | assetsDirExists := true |
| 191 | fi, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Statscip-go gomod github.com/golang/go/src go1.24.0 os/Stat().(assetsDir) |
| 192 | if err != nil { |
| 193 | if osscip-go gomod github.com/golang/go/src go1.24.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.24.0 os/IsNotExist().(err) { |
| 194 | assetsDirExists = false |
| 195 | } else { |
| 196 | return nil, err |
| 197 | } |
| 198 | } else { |
| 199 | assetsDirExists = fi.IsDirscip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#IsDir().() |
| 200 | } |
| 201 | if assetsDirExists { |
| 202 | // if assets is a symlink, follow the symlink. |
| 203 | assetsDir, err = filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.EvalSymlinksscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/EvalSymlinks().(assetsDir) |
| 204 | if err != nil { |
| 205 | return nil, err |
| 206 | } |
| 207 | err = filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Walkscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Walk().(assetsDir, func(path string, info osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.24.0 os/FileInfo#, err error) error { |
| 208 | if err != nil { |
| 209 | return err |
| 210 | } |
| 211 | if name := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Base().(path); stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(name, ".") { |
| 212 | // Do not include the hidden files. |
| 213 | return nil |
| 214 | } |
| 215 | if info.IsDirscip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#IsDir().() { |
| 216 | return nil |
| 217 | } |
| 218 | |
| 219 | if rel, err := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Relscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Rel().(assetsDir, path); rel == "icon.png" && err == nil { |
| 220 | arsc.iconPath = path |
| 221 | // TODO returning here does not write the assets/icon.png to the final assets output, |
| 222 | // making it unavailable via the assets API. Should the file be duplicated into assets |
| 223 | // or should assets API be able to retrieve files from the generated resource table? |
| 224 | return nil |
| 225 | } |
| 226 | |
| 227 | name := "assets/" + path[len(assetsDir)+1:] |
| 228 | return apkwWriteFile(name, path) |
| 229 | }) |
| 230 | if err != nil { |
| 231 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("asset %v", err) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | bxml, err := binresscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/.UnmarshalXMLscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/UnmarshalXML().(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewReader().(manifestData), arsc.iconPath != "") |
| 236 | if err != nil { |
| 237 | return nil, err |
| 238 | } |
| 239 | |
| 240 | // generate resources.arsc identifying single xxxhdpi icon resource. |
| 241 | if arsc.iconPath != "" { |
| 242 | pkgname, err := bxml.RawValueByNamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/XML#RawValueByName().("manifest", xmlscip-go gomod github.com/golang/go/src go1.24.0 `encoding/xml`/.Namescip-go gomod github.com/golang/go/src go1.24.0 `encoding/xml`/Name#{Localscip-go gomod github.com/golang/go/src go1.24.0 `encoding/xml`/Name#Local.: "package"}) |
| 243 | if err != nil { |
| 244 | return nil, err |
| 245 | } |
| 246 | tbl, name := binresscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/.NewMipmapTablescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/NewMipmapTable().(pkgname) |
| 247 | if err := apkwWriteFile(name, arsc.iconPath); err != nil { |
| 248 | return nil, err |
| 249 | } |
| 250 | w, err := apkwCreate("resources.arsc") |
| 251 | if err != nil { |
| 252 | return nil, err |
| 253 | } |
| 254 | bin, err := tbl.MarshalBinaryscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/Table#MarshalBinary().() |
| 255 | if err != nil { |
| 256 | return nil, err |
| 257 | } |
| 258 | if _, err := w.Writescip-go gomod github.com/golang/go/src go1.24.0 io/Writer#Write().(bin); err != nil { |
| 259 | return nil, err |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | w, err = apkwCreate("AndroidManifest.xml") |
| 264 | if err != nil { |
| 265 | return nil, err |
| 266 | } |
| 267 | bin, err := bxml.MarshalBinaryscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/internal/binres`/XML#MarshalBinary().() |
| 268 | if err != nil { |
| 269 | return nil, err |
| 270 | } |
| 271 | if _, err := w.Writescip-go gomod github.com/golang/go/src go1.24.0 io/Writer#Write().(bin); err != nil { |
| 272 | return nil, err |
| 273 | } |
| 274 | |
| 275 | // TODO: add gdbserver to apk? |
| 276 | |
| 277 | if !buildNscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/buildN. { |
| 278 | if err := apkw.Closescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/Writer#Close().(); err != nil { |
| 279 | return nil, err |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // TODO: return nmpkgs |
| 284 | return nmpkgs[targets[0].archscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/targetInfo#arch.], nil |
| 285 | } |
| 286 | |
| 287 | // androidPkgName sanitizes the go package name to be acceptable as a android |
| 288 | // package name part. The android package name convention is similar to the |
| 289 | // java package name convention described in |
| 290 | // https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.5.3.1 |
| 291 | // but not exactly same. |
| 292 | func androidPkgNamescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/androidPkgName().(name string) string { |
| 293 | var res []rune |
| 294 | for _, r := range name { |
| 295 | switch { |
| 296 | case 'a' <= r && r <= 'z', 'A' <= r && r <= 'Z', '0' <= r && r <= '9': |
| 297 | res = append(res, r) |
| 298 | default: |
| 299 | res = append(res, '_') |
| 300 | } |
| 301 | } |
| 302 | if len(res) == 0 || res[0] == '_' || ('0' <= res[0] && res[0] <= '9') { |
| 303 | // Android does not seem to allow the package part starting with _. |
| 304 | res = append([]rune{'g', 'o'}, res...) |
| 305 | } |
| 306 | s := string(res) |
| 307 | // Look for Java keywords that are not Go keywords, and avoid using |
| 308 | // them as a package name. |
| 309 | // |
| 310 | // This is not a problem for normal Go identifiers as we only expose |
| 311 | // exported symbols. The upper case first letter saves everything |
| 312 | // from accidentally matching except for the package name. |
| 313 | // |
| 314 | // Note that basic type names (like int) are not keywords in Go. |
| 315 | switch s { |
| 316 | case "abstract", "assert", "boolean", "byte", "catch", "char", "class", |
| 317 | "do", "double", "enum", "extends", "final", "finally", "float", |
| 318 | "implements", "instanceof", "int", "long", "native", "private", |
| 319 | "protected", "public", "short", "static", "strictfp", "super", |
| 320 | "synchronized", "this", "throw", "throws", "transient", "try", |
| 321 | "void", "volatile", "while": |
| 322 | s += "_" |
| 323 | } |
| 324 | return s |
| 325 | } |
| 326 | |
| 327 | // A random uninteresting private key. |
| 328 | // Must be consistent across builds so newer app versions can be installed. |
| 329 | const debugCertscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/cmd/gomobile`/debugCert. = ` |
| 330 | -----BEGIN RSA PRIVATE KEY----- |
| 331 | MIIEowIBAAKCAQEAy6ItnWZJ8DpX9R5FdWbS9Kr1U8Z7mKgqNByGU7No99JUnmyu |
| 332 | NQ6Uy6Nj0Gz3o3c0BXESECblOC13WdzjsH1Pi7/L9QV8jXOXX8cvkG5SJAyj6hcO |
| 333 | LOapjDiN89NXjXtyv206JWYvRtpexyVrmHJgRAw3fiFI+m4g4Qop1CxcIF/EgYh7 |
| 334 | rYrqh4wbCM1OGaCleQWaOCXxZGm+J5YNKQcWpjZRrDrb35IZmlT0bK46CXUKvCqK |
| 335 | x7YXHgfhC8ZsXCtsScKJVHs7gEsNxz7A0XoibFw6DoxtjKzUCktnT0w3wxdY7OTj |
| 336 | 9AR8mobFlM9W3yirX8TtwekWhDNTYEu8dwwykwIDAQABAoIBAA2hjpIhvcNR9H9Z |
| 337 | BmdEecydAQ0ZlT5zy1dvrWI++UDVmIp+Ve8BSd6T0mOqV61elmHi3sWsBN4M1Rdz |
| 338 | 3N38lW2SajG9q0fAvBpSOBHgAKmfGv3Ziz5gNmtHgeEXfZ3f7J95zVGhlHqWtY95 |
| 339 | JsmuplkHxFMyITN6WcMWrhQg4A3enKLhJLlaGLJf9PeBrvVxHR1/txrfENd2iJBH |
| 340 | FmxVGILL09fIIktJvoScbzVOneeWXj5vJGzWVhB17DHBbANGvVPdD5f+k/s5aooh |
| 341 | hWAy/yLKocr294C4J+gkO5h2zjjjSGcmVHfrhlXQoEPX+iW1TGoF8BMtl4Llc+jw |
| 342 | lKWKfpECgYEA9C428Z6CvAn+KJ2yhbAtuRo41kkOVoiQPtlPeRYs91Pq4+NBlfKO |
| 343 | 2nWLkyavVrLx4YQeCeaEU2Xoieo9msfLZGTVxgRlztylOUR+zz2FzDBYGicuUD3s |
| 344 | EqC0Wv7tiX6dumpWyOcVVLmR9aKlOUzA9xemzIsWUwL3PpyONhKSq7kCgYEA1X2F |
| 345 | f2jKjoOVzglhtuX4/SP9GxS4gRf9rOQ1Q8DzZhyH2LZ6Dnb1uEQvGhiqJTU8CXxb |
| 346 | 7odI0fgyNXq425Nlxc1Tu0G38TtJhwrx7HWHuFcbI/QpRtDYLWil8Zr7Q3BT9rdh |
| 347 | moo4m937hLMvqOG9pyIbyjOEPK2WBCtKW5yabqsCgYEAu9DkUBr1Qf+Jr+IEU9I8 |
| 348 | iRkDSMeusJ6gHMd32pJVCfRRQvIlG1oTyTMKpafmzBAd/rFpjYHynFdRcutqcShm |
| 349 | aJUq3QG68U9EAvWNeIhA5tr0mUEz3WKTt4xGzYsyWES8u4tZr3QXMzD9dOuinJ1N |
| 350 | +4EEumXtSPKKDG3M8Qh+KnkCgYBUEVSTYmF5EynXc2xOCGsuy5AsrNEmzJqxDUBI |
| 351 | SN/P0uZPmTOhJIkIIZlmrlW5xye4GIde+1jajeC/nG7U0EsgRAV31J4pWQ5QJigz |
| 352 | 0+g419wxIUFryGuIHhBSfpP472+w1G+T2mAGSLh1fdYDq7jx6oWE7xpghn5vb9id |
| 353 | EKLjdwKBgBtz9mzbzutIfAW0Y8F23T60nKvQ0gibE92rnUbjPnw8HjL3AZLU05N+ |
| 354 | cSL5bhq0N5XHK77sscxW9vXjG0LJMXmFZPp9F6aV6ejkMIXyJ/Yz/EqeaJFwilTq |
| 355 | Mc6xR47qkdzu0dQ1aPm4XD7AWDtIvPo/GG2DKOucLBbQc2cOWtKS |
| 356 | -----END RSA PRIVATE KEY----- |
| 357 | ` |