"""Notes:1 - This script it for python32 - Create a backup first3 - Place on the root folder of the android project you want to change4 - run `python change_android_studio_pkg_name.py`5 - Type the old package name6 - Type the new package name7 - Clean and Rebuild on Android Studio8 - SRC folder names won't be changed but app will work"""
import os, glob, tracebackfrom pathlib import Path
def rwf(fp, mode="r", data="" ):if mode == "r":with open(fp, "r", encoding='utf8') as f:return(f.read())elif mode == "w":with open(fp, "w", encoding='utf8') as f:f.write(data)
old_pkg = input("Old PKG\n").strip()new_pkg = input("New PKG\n").strip()
if not old_pkg or not new_pkg:exit("Args Missing")
dirname, filename = os.path.split(os.path.abspath(__file__))file_types = ['xml', 'txt', 'json', 'gradle', 'java']_fs = glob.iglob(f"{dirname}/**", recursive=True)for file_path in _fs:ext = Path(file_path).suffix.replace(".", "").lower()if os.path.isfile(file_path) and ext in file_types:try:content = rwf(file_path)new_content = content.replace(old_pkg, new_pkg)rwf(file_path, "w", new_content)except:print(traceback.format_exc())pass
android {defaultConfig {applicationId "com.example.myapplication"}}and package name the same. package="com.example.myapplication"
第2步在我的情况下删除iml文件:
Go To Project> >C:\Users\ashif\Documents\MyApplication .iml file // deleteif you forget Project Path Then Go To android Studio Right Click on app and go to Show in Explorer you get your Project and remove .iml file
第3步关闭项目
第4步现在复制您的旧项目并粘贴任何其他根或复制项目文件夹并粘贴任何其他导演。
Example C:\Users\ashif\Documents/MyApplication
步骤5
Now open Android Studio and open Existing ProjectC:\Users\ashif\Documents/MyApplication