android: fix and test compilation to raw Android C code (#13080)
parent
a73e1462f0
commit
17911432b9
|
@ -41,6 +41,11 @@ jobs:
|
||||||
./v -os windows cmd/v
|
./v -os windows cmd/v
|
||||||
./v -os windows examples/2048/2048.v
|
./v -os windows examples/2048/2048.v
|
||||||
|
|
||||||
|
- name: Compile to raw Android (non-graphic) compatible
|
||||||
|
run: |
|
||||||
|
# Test that V can compile non-graphic app to Android compatible code *without* using the -apk flag
|
||||||
|
./v -os android examples/toml.v
|
||||||
|
|
||||||
linux-cross:
|
linux-cross:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
|
@ -88,6 +93,12 @@ jobs:
|
||||||
./v -os windows examples/2048/2048.v
|
./v -os windows examples/2048/2048.v
|
||||||
ls -lart examples/2048/2048.exe
|
ls -lart examples/2048/2048.exe
|
||||||
|
|
||||||
|
- name: toml.v can be compiled to raw Android C
|
||||||
|
run: |
|
||||||
|
# Test that V can compile non-graphic app to Android compatible code *without* using the -apk flag
|
||||||
|
./v -os android examples/toml.v
|
||||||
|
|
||||||
|
|
||||||
windows-cross:
|
windows-cross:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
|
|
|
@ -19,21 +19,25 @@ fn C.AAsset_read(&C.AAsset, voidptr, int) int
|
||||||
fn C.AAsset_close(&C.AAsset)
|
fn C.AAsset_close(&C.AAsset)
|
||||||
|
|
||||||
pub fn read_apk_asset(file string) ?[]byte {
|
pub fn read_apk_asset(file string) ?[]byte {
|
||||||
act := &C.ANativeActivity(C.sapp_android_get_native_activity())
|
$if apk {
|
||||||
if isnil(act) {
|
act := &C.ANativeActivity(C.sapp_android_get_native_activity())
|
||||||
return error('Could not get reference to Android activity')
|
if isnil(act) {
|
||||||
}
|
return error('Could not get reference to Android activity')
|
||||||
asset := C.AAssetManager_open(&C.AAssetManager(act.assetManager), file.str, C.AASSET_MODE_STREAMING)
|
|
||||||
if isnil(asset) {
|
|
||||||
return error('File `$file` not found')
|
|
||||||
}
|
|
||||||
len := C.AAsset_getLength(asset)
|
|
||||||
buf := []byte{len: len}
|
|
||||||
for {
|
|
||||||
if C.AAsset_read(asset, buf.data, len) > 0 {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
asset := C.AAssetManager_open(&C.AAssetManager(act.assetManager), file.str, C.AASSET_MODE_STREAMING)
|
||||||
|
if isnil(asset) {
|
||||||
|
return error('File `$file` not found')
|
||||||
|
}
|
||||||
|
len := C.AAsset_getLength(asset)
|
||||||
|
buf := []byte{len: len}
|
||||||
|
for {
|
||||||
|
if C.AAsset_read(asset, buf.data, len) > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
C.AAsset_close(asset)
|
||||||
|
return buf
|
||||||
|
} $else {
|
||||||
|
return error(@FN + ' can only be used with APK/AAB packaged Android apps')
|
||||||
}
|
}
|
||||||
C.AAsset_close(asset)
|
|
||||||
return buf
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue