Android DFU doesn't find firmware in assets folder

Hello!

I am in the process of adding OTA DFU support to our existing application. However, I'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 the DFU process I get an error about the file not being found:

I am using DFU version 2.1.0, "targetSDK 31" and "compileSDK 32".

The test device is a Samsung Galaxy S10+ with Android 12.

Here is the code that starts the DFU process:

I have also added DFUService from the GitHub page:

As well as a NotificationActivity:

I have also added those to the manifest:

Can anyone tell me what I'm doing wrong?

Best regards
Magnus Johansen

Parents
  • Hi Magnus, 
    I was checking with the developer and got the following suggestion: 

    Based on this: https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java#L1474

    The assets file has to be given as Uri, not Path.

    This method is called when the “FileUri” is not null:
    https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java#L1198-L1204

     

    Therefore, I think it may be enough for the customer to change

    starter.setZip("file:///android_assets/firmware.zip")

     

    to

     

    starter.setZip(Uri.parse("file:///android_assets/firmware.zip"))

     

    to use this method https://github.com/NordicSemiconductor/Android-DFU-Library/blob/38dad6229fa949dca090cfc8a65aa26f0e4ea7f9/lib_dfu/src/main/java/no/nordicsemi/android/dfu/DfuServiceInitiator.java#L647-L649 instead of the one below.

  • Hello Hung Bui!

    Thank you for a great response, however, it did not solve our problem.

    I changed the code in the DfuServiceInitiator:

    However, I still got (almost) the same error:

    Here you can see that the file is in the assets folder in our project:

    Do you, or the developer, have any other suggestions?

    - Magnus

  • Update on the current situation:

    I have attempted to do the update by copying the zip file to my device and then opening the file in the application.

    That resulted in the following error:

    I found this issue on the GitHub page for the DFU library, and added the solution proposed by the user "nijat2018":

    Then the application successfully updated the device over DFU.

    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.

    - Magnus

  • Hi, did you try res/raw folder instead? You may then pass the reference to zip file as R.raw.firmware.

  • You may also set the notification channel by calling DfuServiceInitiator.createDfuNotificationChannel(context), instead of disabling them if you want.

  • Thank you Aleksander!

    That worked!

    I also enabled the notification channel as you suggested in your other answer, which also worked.

Reply Children