Cordova adds unwanted permission to AndroidManifest.xml when building from CLI

前端 未结 6 901
Happy的楠姐
Happy的楠姐 2021-01-18 07:13

I use CLI to build my Cordova app, and I have added the Media plugin.

\'cordova build\' automatically adds the android.permission.RECORD_AUDIO to my AndroidManifest.

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 08:00

    A clone of Steve-e-b's answer for those who are more comfortable with python. It assumes the file will be located under something like hooks/after_prepare/123_remove_permissions.py and be executable.

    #!/usr/bin/env python
    import os
    
    script_dir = os.path.dirname(os.path.abspath(__file__))
    project_dir = os.path.abspath(os.path.join(script_dir, '../..'))
    
    bad_permissions = [
        'WRITE_EXTERNAL_STORAGE',
        'RECORD_AUDIO',
        'MODIFY_AUDIO_SETTINGS',
    ]
    
    android_manifest = os.path.join(project_dir, 'platforms/android/app/src/main/AndroidManifest.xml')
    
    with open(android_manifest, 'r') as fr:
        lines = fr.readlines()
    
    new_lines = [line for line in lines if not [perm for perm in bad_permissions if perm in line]]
    
    with open(android_manifest, 'w') as fw:
        fw.writelines(new_lines)
    

提交回复
热议问题