-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-116622: Add Android testbed #117878
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
Merged
Merged
gh-116622: Add Android testbed #117878
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
625a6aa
Empty project generated by Android Studio Hedgehog
mhsmith 4a6affe
Add testbed implementation
mhsmith ad058fe
Add test instructions to README; update CODEOWNERS
mhsmith d76913d
Add news entry
mhsmith 88bfca8
Replace default icons with a single Pytho n icon
mhsmith d69be6d
Update Gradle wrapper to version 8.7
mhsmith 68bc334
Remove Gradle wrapper
mhsmith 00ff14f
Add android.py subcommand to download Gradle wrapper
mhsmith a464627
Prune unnecessary testbed files
mhsmith c88764f
Switch android.py from wget to curl, and list required tools in README
mhsmith 0ac21cd
Update Android/README.md
mhsmith 206eb63
Optimize launcher icon PNG
mhsmith c61cc59
Apply suggestions from code review
mhsmith 1396f3a
More README clarifications
mhsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The Gradle wrapper should be downloaded by running `../android.py setup-testbed`. | ||
/gradlew | ||
/gradlew.bat | ||
/gradle/wrapper/gradle-wrapper.jar | ||
|
||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/deploymentTargetDropdown.xml | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import com.android.build.api.variant.* | ||
|
||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
val PYTHON_DIR = File(projectDir, "../../..").canonicalPath | ||
val PYTHON_CROSS_DIR = "$PYTHON_DIR/cross-build" | ||
val ABIS = mapOf( | ||
"arm64-v8a" to "aarch64-linux-android", | ||
"x86_64" to "x86_64-linux-android", | ||
) | ||
|
||
val PYTHON_VERSION = File("$PYTHON_DIR/Include/patchlevel.h").useLines { | ||
for (line in it) { | ||
val match = """#define PY_VERSION\s+"(\d+\.\d+)""".toRegex().find(line) | ||
if (match != null) { | ||
return@useLines match.groupValues[1] | ||
} | ||
} | ||
throw GradleException("Failed to find Python version") | ||
} | ||
|
||
|
||
android { | ||
namespace = "org.python.testbed" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "org.python.testbed" | ||
minSdk = 21 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
ndk.abiFilters.addAll(ABIS.keys) | ||
externalNativeBuild.cmake.arguments( | ||
"-DPYTHON_CROSS_DIR=$PYTHON_CROSS_DIR", | ||
"-DPYTHON_VERSION=$PYTHON_VERSION") | ||
} | ||
|
||
externalNativeBuild.cmake { | ||
path("src/main/c/CMakeLists.txt") | ||
} | ||
|
||
// Set this property to something non-empty, otherwise it'll use the default | ||
// list, which ignores asset directories beginning with an underscore. | ||
aaptOptions.ignoreAssetsPattern = ".git" | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation("androidx.appcompat:appcompat:1.6.1") | ||
implementation("com.google.android.material:material:1.11.0") | ||
implementation("androidx.constraintlayout:constraintlayout:2.1.4") | ||
} | ||
|
||
|
||
// Create some custom tasks to copy Python and its standard library from | ||
// elsewhere in the repository. | ||
androidComponents.onVariants { variant -> | ||
generateTask(variant, variant.sources.assets!!) { | ||
into("python") { | ||
for (triplet in ABIS.values) { | ||
for (subDir in listOf("include", "lib")) { | ||
into(subDir) { | ||
from("$PYTHON_CROSS_DIR/$triplet/prefix/$subDir") | ||
include("python$PYTHON_VERSION/**") | ||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
} | ||
} | ||
} | ||
into("lib/python$PYTHON_VERSION") { | ||
// Uncomment this to pick up edits from the source directory | ||
// without having to rerun `make install`. | ||
// from("$PYTHON_DIR/Lib") | ||
// duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
|
||
into("site-packages") { | ||
from("$projectDir/src/main/python") | ||
} | ||
} | ||
} | ||
exclude("**/__pycache__") | ||
} | ||
|
||
generateTask(variant, variant.sources.jniLibs!!) { | ||
for ((abi, triplet) in ABIS.entries) { | ||
into(abi) { | ||
from("$PYTHON_CROSS_DIR/$triplet/prefix/lib") | ||
include("libpython*.*.so") | ||
include("lib*_python.so") | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
fun generateTask( | ||
variant: ApplicationVariant, directories: SourceDirectories, | ||
configure: GenerateTask.() -> Unit | ||
) { | ||
val taskName = "generate" + | ||
listOf(variant.name, "Python", directories.name) | ||
.map { it.replaceFirstChar(Char::uppercase) } | ||
.joinToString("") | ||
|
||
directories.addGeneratedSourceDirectory( | ||
tasks.register<GenerateTask>(taskName) { | ||
into(outputDir) | ||
configure() | ||
}, | ||
GenerateTask::outputDir) | ||
} | ||
|
||
|
||
// addGeneratedSourceDirectory requires the task to have a DirectoryProperty. | ||
abstract class GenerateTask: Sync() { | ||
@get:OutputDirectory | ||
abstract val outputDir: DirectoryProperty | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.Material3.Light.NoActionBar"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.4.1) | ||
project(testbed) | ||
|
||
set(PREFIX_DIR ${PYTHON_CROSS_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}/prefix) | ||
include_directories(${PREFIX_DIR}/include/python${PYTHON_VERSION}) | ||
link_directories(${PREFIX_DIR}/lib) | ||
link_libraries(log python${PYTHON_VERSION}) | ||
|
||
add_library(main_activity SHARED main_activity.c) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.