Some problems occurred when I try to customize my AI model in the Flower Android Example (TensorFlowLite) app

I have read the only two posts tagged with android in this forum.
And also I have read the articles mentioned in the above two posts.

After I cloned the code repository of Flower Android Example (TensorFlowLite) (flower/examples/android at main · adap/flower · GitHub),

I successfully run the flower-client.apk built-in in this code repository, but when I tried to modify this Android source code, I encountered the following problems:

(1) The version of Tensorflow-Lite in build.gradle is specified as 0.0.0 (i.e. an invalid version is specified), and I don’t know which version should be specified as appropriate.

I’m asking this because when I try to fill in some existing versions, there are always errors. For example, filling in 2.2.0 will result in the following error

Summary
D:\GitProjects\FlowerAndroidDemo\android\client\transfer_api\src\androidTest\java\org\tensorflow\lite\examples\transfer\api\ModelCorrectnessTest.java:71: Error: Unable to apply the method addSample in the TransferLearningModel class to the given type;
        model.addSample(jpgBytesToRgb(zipFiles.get(sample.imagePath)), sample.className).get();
             ^
  Need: float[],String,Boolean
  Found:    float[],String
  Cause: The actual parameter list and the formal parameter list have different lengths
1  Error
3  Warnings

FAILURE: Build completed with 3 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':transfer_api:mergeDebugAndroidTestNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
   > 2 files found with path 'lib/arm64-v8a/libtensorflowlite_jni.so' from inputs:
      - C:\Users\MYUSERNAME\.gradle\caches\8.9\transforms\b366b0b2e85279058b3f762d0939a4c2\transformed\jetified-tensorflow-lite-2.2.0\jni\arm64-v8a\libtensorflowlite_jni.so
      - C:\Users\MYUSERNAME\.gradle\caches\8.9\transforms\d9de7ef4a89d97199f8797e45ddd6bec\transformed\jetified-litert-1.1.2\jni\arm64-v8a\libtensorflowlite_jni.so
     If you are using jniLibs and CMake IMPORTED targets, see
     https://developer.android.com/r/tools/jniLibs-vs-imported-targets

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':transfer_api:checkDebugAndroidTestDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class org.tensorflow.lite.DataType found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.DataType$1 found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.Delegate found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.Interpreter found in modules litert-1.1.2.aar -> jetified-litert-1.1.2-runtime (com.google.ai.edge.litert:litert:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.Interpreter$Options found in modules litert-1.1.2.aar -> jetified-litert-1.1.2-runtime (com.google.ai.edge.litert:litert:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.NativeInterpreterWrapper found in modules litert-1.1.2.aar -> jetified-litert-1.1.2-runtime (com.google.ai.edge.litert:litert:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.Tensor found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.Tensor$QuantizationParams found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.TensorFlowLite found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.annotations.UsedByReflection found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.nnapi.NnApiDelegate found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     Duplicate class org.tensorflow.lite.nnapi.NnApiDelegate$Options found in modules litert-api-1.1.2.aar -> jetified-litert-api-1.1.2-runtime (com.google.ai.edge.litert:litert-api:1.1.2) and tensorflow-lite-2.2.0.aar -> jetified-tensorflow-lite-2.2.0-runtime (org.tensorflow:tensorflow-lite:2.2.0)
     
     Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================

3: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':transfer_api:compileDebugAndroidTestJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --info option to get more log output.
> Run with --scan to get full insights.
==============================================================================

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.9/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 1m 9s
47 actionable tasks: 10 executed, 37 up-to-date

(2) What shall I do if I want to change the model in Flower Android Example (TensorFlowLite) to my own model? I’m asking this because the tutorial mentioned above only describes how to run the program, but does not describe how to modify the program when programming on Android platform.

(3) Although you have SDK documentation about the flwr framework (dev.flower.android), .However, neither the Flower Android Example (TensorFlowLite) nor the Flower Android Client Example with Kotlin and TensorFlow Lite 2022 seem to reference this SDK. I want to know where this SDK document is used?

1 Like