<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Android DFU doesn&amp;#39;t find firmware in assets folder</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94661/android-dfu-doesn-t-find-firmware-in-assets-folder</link><description>Hello! 
 I am in the process of adding OTA DFU support to our existing application. However, I&amp;#39;m having problems starting the DFU process. 
 For security reasons we want to embed the firmware file in the Android application, but when attempting to start</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Dec 2022 15:36:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94661/android-dfu-doesn-t-find-firmware-in-assets-folder" /><item><title>RE: Android DFU doesn't find firmware in assets folder</title><link>https://devzone.nordicsemi.com/thread/400430?ContentTypeID=1</link><pubDate>Tue, 13 Dec 2022 15:36:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:465de661-b217-4560-a2ce-65c229d8fd2b</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Cool! Btw, the difference between assets and res is that the resources are getting compressed in the APK, so are preferred. Glad that it works!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android DFU doesn't find firmware in assets folder</title><link>https://devzone.nordicsemi.com/thread/400424?ContentTypeID=1</link><pubDate>Tue, 13 Dec 2022 15:18:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d268c97e-7891-408f-a0ec-8f8a42d76125</guid><dc:creator>stmj12</dc:creator><description>&lt;p&gt;Thank you Aleksander!&lt;/p&gt;
&lt;p&gt;That worked!&lt;/p&gt;
&lt;p&gt;I also enabled the notification channel as you suggested in your other answer, which also worked.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android DFU doesn't find firmware in assets folder</title><link>https://devzone.nordicsemi.com/thread/400372?ContentTypeID=1</link><pubDate>Tue, 13 Dec 2022 12:19:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77ff8bf7-ea06-48e3-8ba3-72a83c6f5dd1</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;You may also set the notification channel by calling &lt;strong&gt;DfuServiceInitiator.createDfuNotificationChannel(context)&lt;/strong&gt;, instead of disabling them if you want.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android DFU doesn't find firmware in assets folder</title><link>https://devzone.nordicsemi.com/thread/400366?ContentTypeID=1</link><pubDate>Tue, 13 Dec 2022 12:12:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc076060-613f-4f87-a106-41cb8eb20bd2</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Hi, did you try &lt;strong&gt;res/raw&lt;/strong&gt; folder instead? You may then pass the reference to zip file as &lt;em&gt;R.raw.firmware.&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android DFU doesn't find firmware in assets folder</title><link>https://devzone.nordicsemi.com/thread/400205?ContentTypeID=1</link><pubDate>Mon, 12 Dec 2022 15:24:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3fcc662-8154-4243-bce6-7a98064e85aa</guid><dc:creator>stmj12</dc:creator><description>&lt;p&gt;Update on the current situation:&lt;/p&gt;
&lt;p&gt;I have attempted to do the update by copying the zip file to my device and then opening the file in the application.&lt;/p&gt;
&lt;p&gt;That resulted in the following error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ***, PID: 22018
    android.app.RemoteServiceException: Bad notification for startForeground
        at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2155)
        at android.app.ActivityThread.access$2900(ActivityThread.java:315)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2381)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8751)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
I/Process: Sending signal. PID: 22018 SIG: 9
Disconnected from the target VM, address: &amp;#39;localhost:55854&amp;#39;, transport: &amp;#39;socket&amp;#39;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I found&amp;nbsp;&lt;a href="https://github.com/NordicSemiconductor/Android-DFU-Library/issues/106" rel="noopener noreferrer" target="_blank"&gt;this issue&lt;/a&gt;&amp;nbsp;on the GitHub page for the DFU library, and added the solution proposed by the user &amp;quot;nijat2018&amp;quot;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;fun install(context: Context, advertisement: Advertisement, uri: Uri): DfuServiceController {
    val starter = DfuServiceInitiator(advertisement.address).apply {
        setDeviceName(advertisement.name)

        setKeepBond(false)
        setForceDfu(false)

        setForceScanningForNewAddressInLegacyDfu(false)
        setPrepareDataObjectDelay(400L)
        setRebootTime(0L)
        setScanTimeout(2_000L)
        setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)

        setPacketsReceiptNotificationsEnabled(false)
        setPacketsReceiptNotificationsValue(12)
    }

    starter.setZip(uri)
    starter.setForeground(false)
    starter.setDisableNotification(true)
    return starter.start(context, DFUService::class.java)
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then the application&amp;nbsp;successfully updated&amp;nbsp;the device over DFU.&lt;/p&gt;
&lt;p&gt;Now I have verified that the DFU functionality works, so all that remains is to be able to update from the zip file contained in the assets folder in the project.&lt;/p&gt;
&lt;p&gt;- Magnus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android DFU doesn't find firmware in assets folder</title><link>https://devzone.nordicsemi.com/thread/399993?ContentTypeID=1</link><pubDate>Fri, 09 Dec 2022 16:55:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fcf8430a-7b41-4bd1-8517-1d773f255e7f</guid><dc:creator>stmj12</dc:creator><description>&lt;p&gt;Hello Hung Bui!&lt;/p&gt;
&lt;p&gt;Thank you for a great response, however, it did not solve our problem.&lt;/p&gt;
&lt;p&gt;I changed the code in the DfuServiceInitiator:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;fun install(context: Context, advertisement: Advertisement): DfuServiceController {
    val starter = DfuServiceInitiator(advertisement.address).apply {
        setDeviceName(advertisement.name)

        setKeepBond(false)
        setForceDfu(false)

        setForceScanningForNewAddressInLegacyDfu(false)
        setPrepareDataObjectDelay(400L)
        setRebootTime(0L)
        setScanTimeout(2_000L)
        setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)

        setPacketsReceiptNotificationsEnabled(false)
        setPacketsReceiptNotificationsValue(12)
    }

    starter.setZip(Uri.parse(&amp;quot;file:///android_assets/firmware.zip&amp;quot;))
    return starter.start(context, DFUService::class.java)
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, I still got (almost) the same error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ***, PID: 12973
    android.app.RemoteServiceException: Bad notification for startForeground
        at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2155)
        at android.app.ActivityThread.access$2900(ActivityThread.java:315)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2381)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8751)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/DfuBaseService: An exception occurred while opening file
    java.io.FileNotFoundException: /android_assets/firmware.zip: open failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.open(IoBridge.java:575)
        at java.io.FileInputStream.&amp;lt;init&amp;gt;(FileInputStream.java:160)
        at java.io.FileInputStream.&amp;lt;init&amp;gt;(FileInputStream.java:115)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:1523)
        at no.nordicsemi.android.dfu.DfuBaseService.openInputStream(DfuBaseService.java:1483)
        at no.nordicsemi.android.dfu.DfuBaseService.onHandleIntent(DfuBaseService.java:1199)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
        at libcore.io.Linux.open(Native Method)
        at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273)
        at libcore.io.ForwardingOs.open(ForwardingOs.java:567)
        at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8611)
        at libcore.io.IoBridge.open(IoBridge.java:561)
        at java.io.FileInputStream.&amp;lt;init&amp;gt;(FileInputStream.java:160)&amp;#160;
        at java.io.FileInputStream.&amp;lt;init&amp;gt;(FileInputStream.java:115)&amp;#160;
        at android.content.ContentResolver.openInputStream(ContentResolver.java:1523)&amp;#160;
        at no.nordicsemi.android.dfu.DfuBaseService.openInputStream(DfuBaseService.java:1483)&amp;#160;
        at no.nordicsemi.android.dfu.DfuBaseService.onHandleIntent(DfuBaseService.java:1199)&amp;#160;
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)&amp;#160;
        at android.os.Handler.dispatchMessage(Handler.java:106)&amp;#160;
        at android.os.Looper.loopOnce(Looper.java:226)&amp;#160;
        at android.os.Looper.loop(Looper.java:313)&amp;#160;
        at android.os.HandlerThread.run(HandlerThread.java:67)&amp;#160;
I/Process: Sending signal. PID: 12973 SIG: 9
Disconnected from the target VM, address: &amp;#39;localhost:50997&amp;#39;, transport: &amp;#39;socket&amp;#39;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here you can see that the file is in the assets folder in our project:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/2022_2D00_12_2D00_08-10_5F00_50_5F00_40_2D00_Leveler-_1320_-AndroidManifest.xml-_5B00_Leveler.app.main_5D00_.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Do you, or the developer, have any other suggestions?&lt;/p&gt;
&lt;p&gt;- Magnus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android DFU doesn't find firmware in assets folder</title><link>https://devzone.nordicsemi.com/thread/399944?ContentTypeID=1</link><pubDate>Fri, 09 Dec 2022 13:29:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6f4f7ab-0cda-4a4c-aaa9-357d1ebdabe8</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Magnus,&amp;nbsp;&lt;br /&gt;I was checking with the developer and got the following suggestion:&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Based on this: &lt;a href="https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java#L1474"&gt;https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java#L1474&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The assets file has to be given as Uri, not Path.&lt;/p&gt;
&lt;p&gt;This method is called when the “FileUri” is not null:&lt;br /&gt; &lt;a href="https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java#L1198-L1204"&gt;https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java#L1198-L1204&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Therefore, I think it may be enough for the customer to change&lt;/p&gt;
&lt;p&gt;starter.setZip(&amp;quot;file:///android_assets/firmware.zip&amp;quot;)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;starter.setZip(Uri.parse(&amp;quot;file:///android_assets/firmware.zip&amp;quot;))&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;to use this method &lt;a href="https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuServiceInitiator.java#L647-L649"&gt;https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuServiceInitiator.java#L647-L649&lt;/a&gt; instead of the one below.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>