mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
android: fix and test compilation to raw Android C code (#13080)
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user