question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android Downloads Suddenly Crashes App After Working Fine

See original GitHub issue

ok so my app was working perfect downloading with no issues at all i tried it on a firestick / nvidia shield and android TV emulator and it was working perfect one day but the next day when i opened the app to try it again the app crashes every time a download starts.

this is the version of react-native i am using and the version of rn-fetch-blob

“react-native”: “0.57.8”, “rn-fetch-blob”: “^0.10.15”

i have tried creating a new project and adding in just the modules needed for the downloads and used a static link to an apk file i know works perfectly fine and it does work perfect for a few tries but again when the app is closed and reopened sometime later it crashes again after a download starts.

this is the code for my downloads

console.log("Download Starting");
	
	const android = RNFetchBlob.android;
	const filename = APK_TITLE + ((Math.random() * 1000) | 0) + '.apk';
	const filePath = RNFetchBlob.fs.dirs.DownloadDir + '/' + filename ;
	
	console.log('Saving File To : ' + filePath);
	
	this.setState({AppName: APK_TITLE});
	this.setState({ Mode: 'download' });
	
	let APKDownload = RNFetchBlob.config({
			
			addAndroidDownloads : {
				useDownloadManager : false,
				mediaScannable : true,
				notification : true,
				mime : 'application/vnd.android.package-archive',
				title : filename,
				description : APK_DESC,
				path: filePath
			}
		})
		.fetch('GET', APK_URL);
		
	jobId = APKDownload.taskId;
	console.log(jobId);
	
    setTimeout(()=>{
		
		APKDownload.progress({ count : 1 },(received,total)=>{
			const percentage = (received / total).toFixed(2);
			const text = percentage;
			console.log('Download Progress : ' + text);
			this.setState({progress: text});
		})
    }, 0)
	
    APKDownload.then(async (res)=>{
			
			this.setState({Mode: 'apks'});
			this.setState({AppName: ''});
			this.setState({progress: 0.00});
			
			console.log('Installing APK');
			android.actionViewIntent(res.path(), 'application/vnd.android.package-archive');
		
    }).catch((err)=>{
       //you must add this line. If you don't add, your app users waste they're storage
        //RNFetchBlob.fs.unlink(filePath);
        console.log(err)
    })
	
}

after attaching a debugger in android studio i have found this

I/ReactNativeJS: Download Process Starting
    APK Saving To : /storage/emulated/0/Download/Cyberflixx150.apk
I/ReactNativeJS: Download ID Assigned : wz3qit80wzj2h01bn6n5
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: com.update, PID: 14132
    java.lang.IllegalArgumentException: path can't be null
        at android.app.DownloadManager.validateArgumentIsNonEmpty(DownloadManager.java:1418)
        at android.app.DownloadManager.addCompletedDownload(DownloadManager.java:1375)
        at android.app.DownloadManager.addCompletedDownload(DownloadManager.java:1325)
        at com.RNFetchBlob.RNFetchBlobReq$3.onResponse(RNFetchBlobReq.java:443)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:761)

the path is clearly set and even if i remove the let apk path veriable and set the path in path: still the same error 😕

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
bozhouyongqicommented, Jan 11, 2019

I have solved this problem,but i used the downloadManager.Following is the code:

        const android = RNFetchBlob.android;
        const filename = 'name.apk';
        const filepath = RNFetchBlob.fs.dirs.DownloadDir + '/' + filename;
        const downloadAppUrl = ''http://www.moji.com/android_down.php';';// moji weather apk

        RNFetchBlob.config({
            addAndroidDownloads: {
                useDownloadManager: true,
                title: 'great, download success',
                description:'an apk that will be download',
                mime: 'application/vnd.android.package-archive',
                // mime: 'image/jpeg',
                // mediaScannable: true,
                notification: true,
                path: filepath
            }
        })
        .fetch('GET', downloadAppUrl)
        .then((res) => {
            // console.log('res.path ', res.path());
            alert('res.path ', res.path());
            android.actionViewIntent(res.path(), 'application/vnd.android.package-archive');
        })
        .catch((err) => {
            alert('download error, err is', JSON.stringify(err));
        });

The difference with the official document is that i added the path optional field in the addAndroidDownloads object.When i delete the path field,the it will come into the catch code,then download the app will be wrongly.

the version of react-native i am using and the version of rn-fetch-blob are “react-native”: “0.57.3”, “rn-fetch-blob”: “^0.10.15”, and the os is macOS 10.13.6

0reactions
mahdi-gh1373commented, Feb 5, 2019

@Rob2k9 Could you share your code that resolve this problem ? I need a progress in my app to show user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do my apps keep crashing on Android, How to fix it
How to fix apps that keep crashing on Android · 1. Force stop the app · 2. Restart the device · 4. Reinstall...
Read more >
Why Do My Apps Keep Crashing on Android? - Avast
Restarting your device simply resets the software, which may not solve the original problem. Shutting down your device forces the hardware to ...
Read more >
How to Stop Apps From Crashing on Android - AVG
Press and hold the Power button. · Wait until you see options to Restart or Power off. · Select Restart to start up...
Read more >
11 Quick Ways to Fix Apps Keep Crashing on Android - iMobie
The Most Effective Method to Fix Apps Keep Crashing · Tip 2. Force Stop Crashed App · Tip 3. Keep Apps in the...
Read more >
Apps keep crashing on Android? Here's what to do
Go to Settings > Storage > Other apps > (app name) and tap on Clear cache. There are plenty of other troubleshooting steps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found