Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add --android-target-sdk-version arg (defaults to android_api) #2686

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ def make_package(args):
sdk_dir = fileh.read().strip()
sdk_dir = sdk_dir[8:]

if args.android_target_sdk_version == -1:
args.android_target_sdk_version = android_api
if args.android_target_sdk_version != android_api:
print(f'WARNING: android_target_sdk_version ({args.android_target_sdk_version}) '
f'was set explicitly, and it does not match android_api ({android_api}).')

# Try to build with the newest available build tools
ignored = {".DS_Store", ".ds_store"}
build_tools_versions = [x for x in listdir(join(sdk_dir, 'build-tools')) if x not in ignored]
Expand Down Expand Up @@ -805,6 +811,9 @@ def parse_args_and_make_package(args=None):
action='store_true',
help=('Allow the --minsdk argument to be different from '
'the discovered ndk_api in the dist'))
ap.add_argument('--android-target-sdk-version', dest='android_target_sdk_version',
default=-1, type=int,
help='targetSdkVersion to put in manifest. Matches android-api by default.')
ap.add_argument('--intent-filters', dest='intent_filters',
help=('Add intent-filters xml rules to the '
'AndroidManifest.xml file. The argument is a '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
buildToolsVersion '{{ build_tools_version }}'
defaultConfig {
minSdkVersion {{ args.min_sdk_version }}
targetSdkVersion {{ android_api }}
targetSdkVersion {{ args.android_target_sdk_version }}
versionCode {{ args.numeric_version }}
versionName '{{ args.version }}'
manifestPlaceholders = {{ args.manifest_placeholders}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/>

<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ android_api }}" />
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ args.android_target_sdk_version }}" />

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:versionName="{{ args.version }}">

<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ android_api }}" />
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ args.android_target_sdk_version }}" />

<application {% if debug %}android:debuggable="true"{% endif %} >
{% for name in service_names %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/>

<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ android_api }}" />
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ args.android_target_sdk_version }}" />

<!-- Set permissions -->
{% for perm in args.permissions %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/>

<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ android_api }}" />
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ args.android_target_sdk_version }}" />

<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
4 changes: 3 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class TestTemplates(unittest.TestCase):
def test_android_manifest_xml(self):
args = mock.Mock()
args.min_sdk_version = 12
android_api = 1234
args.android_target_sdk_version = android_api
args.build_mode = 'debug'
args.native_services = ['abcd', ]
args.permissions = []
Expand All @@ -74,7 +76,7 @@ def test_android_manifest_xml(self):
"args": args,
"service": False,
"service_names": [],
"android_api": 1234,
"android_api": android_api,
"debug": "debug" in args.build_mode,
"native_services": args.native_services
}
Expand Down