android: fix and test compilation to raw Android C code (#13080)

pull/13086/head
Larpon 2022-01-07 15:57:05 +01:00 committed by GitHub
parent a73e1462f0
commit 17911432b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 15 deletions

View File

@ -41,6 +41,11 @@ jobs:
./v -os windows cmd/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:
runs-on: ubuntu-20.04
timeout-minutes: 15
@ -88,6 +93,12 @@ jobs:
./v -os windows examples/2048/2048.v
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:
runs-on: windows-2019
timeout-minutes: 15

View File

@ -19,21 +19,25 @@ fn C.AAsset_read(&C.AAsset, voidptr, int) int
fn C.AAsset_close(&C.AAsset)
pub fn read_apk_asset(file string) ?[]byte {
act := &C.ANativeActivity(C.sapp_android_get_native_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
$if apk {
act := &C.ANativeActivity(C.sapp_android_get_native_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
}
}
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
}