Skip to content

Commit

Permalink
vab, cli: notify with remedies for know problems on errors (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon authored Oct 16, 2024
1 parent cce025c commit 43a51e1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
15 changes: 15 additions & 0 deletions android/android.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright(C) 2019-2024 Lars Pontoppidan. All rights reserved.
// Use of this source code is governed by an MIT license file distributed with this software package
module android

pub const default_app_name = $d('vab:default_app_name', 'V Test App')
pub const default_package_id = $d('vab:default_package_id', 'io.v.android')
pub const default_activity_name = $d('vab:default_activity_name', 'VActivity')
pub const default_package_format = $d('vab:default_package_format', 'apk')
pub const default_min_sdk_version = int($d('vab:default_min_sdk_version', 21))
pub const default_base_files_path = get_default_base_files_path()
pub const supported_package_formats = ['apk', 'aab']
pub const supported_lib_folders = ['armeabi', 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
pub const mipmap_icon_sizes = [192, 144, 96, 72, 48]! // xxxhdpi, xxhdpi, xhdpi, hdpi, mdpi

pub type OptionTypes = CompileOptions | PackageOptions | DeployOptions
10 changes: 0 additions & 10 deletions android/package.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ import vab.android.env
import vab.android.sdk
import vab.android.util

pub const default_app_name = $d('vab:default_app_name', 'V Test App')
pub const default_package_id = $d('vab:default_package_id', 'io.v.android')
pub const default_activity_name = $d('vab:default_activity_name', 'VActivity')
pub const default_package_format = $d('vab:default_package_format', 'apk')
pub const default_min_sdk_version = int($d('vab:default_min_sdk_version', 21))
pub const default_base_files_path = get_default_base_files_path()
pub const supported_package_formats = ['apk', 'aab']
pub const supported_lib_folders = ['armeabi', 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
pub const mipmap_icon_sizes = [192, 144, 96, 72, 48]! // xxxhdpi, xxhdpi, xhdpi, hdpi, mdpi

// PackageFormat holds all supported package formats
pub enum PackageFormat {
apk
Expand Down
2 changes: 1 addition & 1 deletion cli/options.v
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ pub fn (mut opt Options) ensure_launch_fields() {
}
}

// validate_env ensures that `Optins` meet all runtime requrements.
// validate_env ensures that `Options` meet all runtime requrements.
pub fn (opt &Options) validate_env() {
// Validate JDK
jdk_version := java.jdk_version()
Expand Down
44 changes: 44 additions & 0 deletions cli/remedy.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module cli

import semver
import vab.util
import vab.android
import vab.extra

// doctor_remedy notifies of known errors and mismatches of various Android SDK/NDK bugs, if detected.
pub fn doctor_remedy(opts android.OptionTypes, err_str string) {
match opts {
android.PackageOptions {
notify_known_package_errors(opts, err_str)
}
else {}
}
}

fn callsite_extra_command(cmd string) string {
if cmd.starts_with(extra.command_prefix + '-') {
return '${extra.command_prefix} ${cmd.all_after(extra.command_prefix + '-')}'
}
return cmd
}

fn notify_known_package_errors(opt android.PackageOptions, err_str string) {
if opt.api_level.i16() >= 35 {
if build_tools_semantic_version := semver.from(opt.build_tools) {
build_tools_version := '34.0.0'
if build_tools_semantic_version.satisfies('<${build_tools_version}') {
symptoms_aab := "\taapt2 E 10-15 19:10:38 93691 93691 LoadedArsc.cpp:96] RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data.
\taapt2 E 10-15 19:10:38 93691 93691 ApkAssets.cpp:500] Failed to load 'resources.arsc' in APK '.../platforms/android-35/android.jar'."
symptoms_apk := "\taapt E 10-15 18:51:31 89712 89712] Entry offset at index 1335 points outside the Type's boundaries
\t.../AndroidManifest.xml:13: error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/Theme.NoTitleBar.Fullscreen').
\t.../res/values/styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light.DarkActionBar'."
symptoms := if opt.format == .aab { symptoms_aab } else { symptoms_apk }
util.vab_notice('Using build-tools < ${build_tools_version} with Android API level >= ${opt.api_level} is known to cause package build errors',
details:
'Symptoms:\n${symptoms}\nIt can usually be fixed by installing and using build-tools >= ${build_tools_version}' +
'\nTry:\n\tvab install "build-tools;${build_tools_version}"\n\t${callsite_extra_command(exe_short_name)} --build-tools "${build_tools_version}" ...'
)
}
}
}
}
1 change: 1 addition & 0 deletions vab.v
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ fn main() {
}
android.package(pck_opt) or {
util.vab_error('Packaging did not succeed', details: '${err}')
cli.doctor_remedy(pck_opt, err.msg()) // Suggest possible fixes to known errors
exit(1)
}

Expand Down

0 comments on commit 43a51e1

Please sign in to comment.