Android Question [SOLVED] Problems with compiled B4A WebGL Library

max123

Well-Known Member
Licensed User
Longtime User
Hi all,

some days ago I released the B4J WebGL Library

Now I'm happy to inform all users that I have almost completed writing the WebGL library for B4A, but now there are some problems converting it as compiled library.

Almost everything works, already some demos have been tested and works well on Android Emulator, at 50-60 FPS or less depending of the scene complexity.
I don't have a super PC, just a Ryzen7 minipc with integrated Vega 8 1.2Ghz video card, and the emulator consume 50-80% of CPU when render pretty complex full scenes, so this is really promising..... I have not yet tested on physical devices but I will do it soon.

The library was developed on top of a B4XPages project, with the inline class everything works, but if I compile the class and then import it into
another instance of the IDE creating another new B4XPages project, some error occours when compile the project.

Because probably there are more issues compiling it as library and use in a new project the compiled library, I will start here showing the first error.

After compiling a new blank project importing the compiled library the compiler show me this error:
B4A Versione: 13.00
Analisi del Codice. (0.09s)
Java Versione: 19
Building folders structure. (0.04s)
Esecuzione azione personalizzata. (0.10s)
Compilazione del codice. (0.13s)
Compilazione del codice di layouts (0.00s)
Organizzazione Librerie. (0.00s)
(AndroidX SDK)
Compilazione risorse (0.12s)
Collegamento risorse (20.40s)
build tools: 34.0.0, android jar: android-34
Compilazione del codice Java prodotto. (0.02s)
Ricerca librerie che necessitano di essere "dexed". (0.01s)
Dex code (2.19s)
Dex merge Error
Error in C:\Android-SDK\tools\..\extras\b4a_local\unpacked-webgl-63871162194874\dex_v1\webgl.zip:classes.dex:
Type b4a.example.b4xbitset is defined multiple times: C:\Android-SDK\tools\..\extras\b4a_local\unpacked-webgl-63871162194874\dex_v1\webgl.zip:classes.dex, C:\Users\Massimo\Documents\PROGETTI_B4A\ESEMPI MIE LIBRERIE\WebGL_Demos\WebGL_Library_Demo\B4A\Objects\dexed\b4a\example\b4xbitset.dex
Compilation failed
Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Android-SDK\tools\..\extras\b4a_local\unpacked-webgl-63871162194874\dex_v1\webgl.zip:classes.dex
at com.android.tools.r8.internal.po.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:1269)
at com.android.tools.r8.D8.main(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:5)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Android-SDK\tools\..\extras\b4a_local\unpacked-webgl-63871162194874\dex_v1\webgl.zip:classes.dex
at Version.fakeStackEntry(Version_8.3.37.java:0)
at com.android.tools.r8.Q.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:5)
at com.android.tools.r8.internal.po.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:244)
at com.android.tools.r8.internal.po.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:90)
at com.android.tools.r8.internal.po.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:909)
at com.android.tools.r8.internal.po.b(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:99)
at com.android.tools.r8.D8.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:1041)
at com.android.tools.r8.D8.b(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:514)
at com.android.tools.r8.D8.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:1076)
at com.android.tools.r8.internal.po.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:1256)
... 1 more
Caused by: com.android.tools.r8.internal.h: Type b4a.example.b4xbitset is defined multiple times: C:\Android-SDK\tools\..\extras\b4a_local\unpacked-webgl-63871162194874\dex_v1\webgl.zip:classes.dex, C:\Users\Massimo\Documents\PROGETTI_B4A\ESEMPI MIE LIBRERIE\WebGL_Demos\WebGL_Library_Demo\B4A\Objects\dexed\b4a\example\b4xbitset.dex
at com.android.tools.r8.internal.X30.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:346)
at com.android.tools.r8.internal.pX.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:232)
at com.android.tools.r8.internal.pX.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:91)
at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056)
at com.android.tools.r8.internal.pX.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:32)
at com.android.tools.r8.graph.q4$a.d(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:6)
at com.android.tools.r8.dex.c.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:264)
at com.android.tools.r8.dex.c.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:222)
at com.android.tools.r8.dex.c.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:219)
at com.android.tools.r8.D8.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:809)
at com.android.tools.r8.D8.d(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:212)
at com.android.tools.r8.D8.c(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:163)
at com.android.tools.r8.internal.po.a(R8_8.3.37_d0b8d9dfe8720e37c27d2233931d9d72dbd696ffd92111cc9b36e58b4baad1cc:906)
... 6 more
It show that b4xbitset is defined multiple times and I don't know because this happen.

Please, someone know the reason for this error ?

Many Thanks
Max
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
Thanks @Erel

you said:
The problem is that all the B4X code, including the code that comes from the b4xlibs, is compiled into the jar

1) Just to know it for future libraries, for me and all users, so this is different than B4J ?
To compile the B4J library, my class I compile as library is on top of B4XPages project, here I don't had the same problem.

In order to build your library as a jar, you will need to create a project that doesn't depend on any b4xlib.
2) The B4A library use some libraries (please see my screenshot), apart the B4XPages.b4xlib itself, it seem only use OkHttpUtils2.b4xlib,
all others seem regular compiled libraries with jar and xml files.
So I had to compile OkHttpUtils2 as library and then import in my library project or just use it as inline class ?

3) If I just use OkHttpUtils2 as inline class (or compile to library and import them) then compile my library in a normal (non B4XPages) project it should work ?

Many Thanks
 

Attachments

  • Screenshot 2024-12-31 122026.png
    Screenshot 2024-12-31 122026.png
    153.5 KB · Views: 17
Last edited:
  • Like
Reactions: byz
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Yes, thanks @Erel for clarifications.

So, do not matter if I compile the library in a B4XPages project ?
Only matter if I import or not other b4xlibs ?

B4J WebGL library is compiled on top of B4XPages, but it do not depends from other b4xlibs, and it is working without problems.

Thanks
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks @Erel ,

now I compiled WebGL library in a non-B4XPages project and works when compiled to library and imported to another project.

Because depend on okHttpUtils2
- I copied/pasted HttpJob and HttpUtils2Service as new inline classes
- I imported OkHttp library from library tab

And BINGO !!!

Finally my problem was solved and now is more clear even for future libraries, the only my doubt is why it works with B4J even when I compile with B4XPages,
note that here I don't use OkHttpUtils2 at all, so there are no b4xlibs dependencies, apart the B4XPages project itself.
The fact that it compiles with B4XPages is making me curious.

For now I'll just implement your advices, so I'll use a Non-B4XPages project on B4A.

Many thanks for your help.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
- I copied/pasted HttpJob and HttpUtils2Service as new inline classes
- I imported OkHttp library from library tab
Don't want to disappoint but your library will most probably fail to compile in projects that depend on OkHttpUtils2.

In the long run, the solution is to move to b4xlibs.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
@Erel This is a very big problem...

because there are no ways to protect the code, so developers will end up to be
unincentivised to write B4X libraries without possibility to protect a very big work.

In my opinion, b4xlibs are very good things, but only for open code.
Please note that I even released some libraries as b4xlibs eg. this one, AsyncCanvas

You are right, after I import OkHttpUtils2, the demo project do not longer works because doubled declaration and the IDE show me the error before I compile.

1) May I can just rename my classes ?
2) May even the OkHttp I Import can do the same conflict or they does no matter because is imported and not inline class ?

1735828325636.png


UPDATE: I just renamed now HttpUtils2Service and HttpJob and all instance names on the inline classes and now
it works in the final project where I import compiled WebGL library, even if I import OkHttpUtils2 and even if I import OkHttp, because it is a regular library,
so the problem seem solved for now.
 
Last edited:
Upvote 0
Top