mikehardy / react-native-update-apk

Update apk from non-play store servers, and update ios from app store in React Native.
MIT License
195 stars 57 forks source link

Couldn't find meta-data for provider with authority #69

Closed fanzhiri closed 2 years ago

fanzhiri commented 2 years ago

安装时闪退

10-13 12:18:33.635 16561 16617 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules 10-13 12:18:33.635 16561 16617 E AndroidRuntime: Process: com.BleWatch, PID: 16561 10-13 12:18:33.635 16561 16617 E AndroidRuntime: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.BleWatch 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:662) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:635) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:441) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at net.mikehardy.rnupdateapk.RNUpdateAPK.installApk(RNUpdateAPK.java:138) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:955) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:206) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at android.os.Looper.loop(Looper.java:296) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232) 10-13 12:18:33.635 16561 16617 E AndroidRuntime: at java.lang.Thread.run(Thread.java:930)

i check the intermediates android/app/build/intermediates/merged_manifests/release/AndroidManifest.xml then i found

   <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.BleWatch.provider"
        android:exported="false"
        android:grantUriPermissions="true" >
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths" />
    </provider>

"com.BleWatch.provider" should be "com.BleWatch.fileprovider"

i don't know how to fix it .

fanzhiri commented 2 years ago

change one line to fix it

node_modules\rn-update-apk\android\src\main\java\net\mikehardy\rnupdateapk\RNUpdateAPK.java

@ReactMethod
    public void installApk(String filePath, String fileProviderAuthority) {

        File file = new File(filePath);
        if (!file.exists()) {
            Log.e("RNUpdateAPK", "installApk: file doe snot exist '" + filePath + "'");
            // FIXME this should take a promise and fail it
            return;
        }

        if (Build.VERSION.SDK_INT >= 24) {
            // API24 and up has a package installer that can handle FileProvider content:// URIs
            Uri contentUri;
            try {
                //contentUri = FileProvider.getUriForFile(getReactApplicationContext(), fileProviderAuthority, file);
                contentUri = FileProvider.getUriForFile(getReactApplicationContext(), fileProviderAuthority+".provider", file);
mikehardy commented 2 years ago

Hmm - that's not necessary for me, I'm still using this module successfully in a project on a regular basis.

   android:authorities="com.BleWatch.provider"

Note that '.provider' is in the authority name, so should be present in the variable fileProviderAuthority

The example app also has always worked for me (though it's probably out of date now...) and works with the code in the repo with this provider definition

https://github.com/mikehardy/react-native-update-apk/blob/8387795f3d3c4882d29101c428010e2ae722bc7d/example/android/app/src/main/AndroidManifest.xml#L33