@@ -81,17 +81,45 @@ def run_project(args: argparse.Namespace) -> None:
8181
8282 # Copy the user's Python code into the project
8383 src_dir = os .path .join (os .getcwd (), "app" )
84- dest_dir = os .path .join (
85- build_dir , "app"
86- ) # You might need to adjust this depending on the project structure
84+
85+ # Adjust the destination directory for Android project
86+ if platform == "android" :
87+ dest_dir = os .path .join (build_dir , "android_template" , "app" , "src" , "main" , "python" , "app" )
88+ elif platform == "ios" :
89+ dest_dir = os .path .join (build_dir , "app" ) # Adjust this based on your iOS project structure
90+
91+ # Create the destination directory if it doesn't exist
92+ os .makedirs (dest_dir , exist_ok = True )
8793 shutil .copytree (src_dir , dest_dir , dirs_exist_ok = True )
8894
8995 # Install any necessary Python packages into the project environment
9096 requirements_file = os .path .join (os .getcwd (), "requirements.txt" )
9197 # TODO: Fill in with actual commands for installing Python packages
9298
9399 # Run the project
94- # TODO: Fill in with actual commands for running the project
100+ if platform == "android" :
101+ # Change to the Android project directory
102+ android_project_dir = os .path .join (build_dir , "android_template" )
103+ os .chdir (android_project_dir )
104+
105+ # Add executable permissions to the gradlew script
106+ gradlew_path = os .path .join (android_project_dir , "gradlew" )
107+ os .chmod (gradlew_path ,
108+ 0o755 ) # this makes the file executable for the user
109+
110+ # Build the Android project and install it on the device
111+ jdk_path = subprocess .check_output (
112+ ["brew" , "--prefix" , "openjdk@17" ]).decode ().strip ()
113+ env = os .environ .copy ()
114+ env ["JAVA_HOME" ] = jdk_path
115+ subprocess .run (["./gradlew" , "installDebug" ], check = True , env = env )
116+
117+ # Run the Android app
118+ # Assumes that the package name of your app is "com.example.myapp" and the main activity is "MainActivity"
119+ # Replace "com.example.myapp" and ".MainActivity" with your actual package name and main activity
120+ subprocess .run (["adb" , "shell" , "am" , "start" , "-n" ,
121+ "com.pythonnative.android_template/.MainActivity" ],
122+ check = True )
95123
96124
97125def clean_project (args : argparse .Namespace ) -> None :
0 commit comments