star-micronics / react-native-star-io10

react-native-star-io10 is a library for supporting application development for Star Micronics devices.
Other
83 stars 54 forks source link

[Android] Issue when generating apk file with command line tools #51

Closed naotoisoda closed 2 years ago

naotoisoda commented 2 years ago

I waned apk file. But, the process is stacked when assembling, though I can run app when doing npx react-native run-android.

Here is what I tried.

1.npx react-native run-android →Complete. The app is available on the android and can print on the printer.

2.I wanted apk file. So, I tried this. react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/generated/assets/react/debug/index.android.bundle --assets-dest ./android/app/build/res/react/debug

./gradlew assembleDebug

→Error occured.

Task :react-native-star-io10:bundleDebugAar FAILED FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':react-native-star-io10:bundleDebugAar'. Error while evaluating property 'hasLocalAarDeps' of task ':react-native-star-io10:bundleDebugAar' Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :react-native-star-io10 project caused this error: C:\XXXXXXXXXXXXXX\PrintApp\node_modules\react-native-star-io10\android\src\lib\stario10.aar

3.Then,i read this article. And ,do this. ・Create a new directory(aar_module) and put the following content into the build.gradle file withing the new directory:

configurations.maybeCreate("default")
artifacts.add("default", file('stario10.aar'))

・Place the stario10.aar into this new directoy.(aar_module) Next to the build.gradle file. ・Add the new created Gradle project to the settings.gradle file: include(':aar-module') ・Include the project in the node_modules\react-native-star-io10\android\build.gradle

- implementation files('src/lib/stario10.aar')
+ implementation(project(":aar-module"))

./gradlew assembleDebug →Error occured.(also doing npx react-native run-android)

No matching configuration of project :aar-module was found. The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:

  • None of the consumable configurations have attributes.
bandit-ibayashi commented 2 years ago

@naotoisoda Thank you for your report. I was able to reproduce your issue. To create an APK, I tried the method of creating an APK file from an AAB file.

The following was tried without changing the original files of our latest SDK package (v1.1), such as bundle.gradle. I have also run it in the example folder.

% react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

To create the aab file. % cd android % ./gradlew bundleDebug

After converting the aab file to an apks file using the bundletool provided by Google, unzip it with the unzip command, which will output an apk file (universal.apk). % bundletool build-apks --mode=universal --bundle=app-debug.aab --output=app-debug.apks % unzip app-debug.apks

I am afraid it is not your way, but I hope it helps.

naotoisoda commented 2 years ago

@bandit-ibayashi Thank you for your support. Thanks to you , I could have made apk file.

Honestly speaking , on the way , I found I was able to distribute my test app by using aab file. So, I used aab file created on the process 4.below. Thus , I didn't use apk file created on the process 6.. The problem I wrote above is occured on creating apk file ,but not occured when creating aab file. But as a result , I could have solved my problem thanks to you. I appreciate your help.

Here is what I tried.

1.Download bundletool at https://github.com/google/bundletool/releases

  1. put bundletool-all-1.9.0.jar file on the directory.
  2. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/ 4.create the aab file.

    cd android
    ./gradlew bundleDebug

    →app-debug.aab was made on the android/app/build/outputs/bundle/debug directory. 5.make universal.apk bundletool build-apks --mode=universal --bundle=app/build/outputs/bundle/debug/app-debug.aab --output=app-debug.apks →app-debug.apks was made on the android directory. 6.unzip unzip app-debug.apks →universal.apk was made on the android directory.

bandit-ibayashi commented 2 years ago

@naotoisoda I am glad to see that you have successfully achieved your goal!

gare-bear commented 2 years ago

@bandit-ibayashi this sounds like a great topic to add to the Wiki once we enable it on this repo.