Android app from Fire doesn't work with AppCompatActivity

LITERALLY, just replace ALL the code in the Android Studio app with nothing (or an unused dummy class), reference your Elements-built .jar, and you should be good. Android doesn’t care which .jar file YourMainActivity was in.

The result would be the same as if you rewrote all your classes in Java and had Android Studio compile them.

Ok thank you for your support and knowledge i will try…

1 Like

I tried…
First testcase
1.I compiled simple app with one Activity in Elemenst
2.Copied .jar to lib folder in Android Studio , add as Library
3.set main activity to my activity apk ran and after that closed imediatelly ( I saw my main activity a while)
But this project doesn’t have dependencies
Missed i something ?

Second testcase
1.I compiled simple app with one Activity in Elemenst with many AppCompatDependencies
2.Copied .jar to lib folder in Android Studio , add as Library
3.set main activity to my activity apk and I can’t build because AS is displaying :


> Task :app:compileDebugJavaWithJavac FAILED
error: error reading C:\Users\mateu\AndroidStudioProjects\MyApplication\app\libs\inprax.pl.androidapplication.jar; line too long
C:\Users\mateu\AndroidStudioProjects\MyApplication\app\build\generated\source\buildConfig\debug\com\example\myapplication\BuildConfig.java:4: error: cannot access com.example.myapplication
package com.example.myapplication;
^
  line too long
1 error
error reading C:\Users\mateu\AndroidStudioProjects\MyApplication\app\libs\inprax.pl.androidapplication.jar; line too long

I think that is related to many classes dex files in jar…
I don’t know and my knowledge is too small to understand it …
Have you got any idea ?

Workaround is not working…
I searched for error like this in AS but without success…

What i find helpful when something crashes is to have a look at the device/crash log (logcat, in this case. tun “adb logcat” from Terminal. Usually (really, always), there is is a crash log with an exception message and a call stack (usually several nested ones).

you might need multi-dex, men tione some 50 messages ago.

Buit the identical AS aop with MainActivity written in Java works? My money isn on the reference nit getting packaged properly. try using (ie accessing) the MainActivity from a dummy class in Java code.

But again, the crash log will tell us what the real issue is,

Also, try build *20230220-203553-elements-develop* (7693660) (or later) after deleting the EBuild package cache at

%APPDATA%..\Local\RemObjects Software\EBuild\Packages\Gradle
~'Library/Application Support/RemObjects Software/EBuild/Packages/Gradle

This has the new Gradle repo URL.It fails to connect for me, but that could (hopefully) be caused bt my flaky hotel wifi, as it works from Safari). If it correctly downloads the packages for you, good. Of it fails to connect for you, too, I’ll have to debug the .NET HTTP(S) network stack when I’m back home/in the office next month.

of course, even if the new URL works for you, I have no idea if it solves your issues — but Eugene seemed to think it made a difference for him, so :crossed_fingers:t3:

Ok i will try tomorrow…

Hi,
Didn’t help.
I removed ~'Library/Application Support/RemObjects Software/EBuild/Packages/Gradle
the behavior is the same (acitivity works , appcompatacitivity doesn’t work - (breakpoint is not resolved).
Maybe Evgeny will give his simple test case - maybe somewhere is difference - I don’t know.
I asked him for his working simple test case.
I compiled and ran it on commit [3bd5cb6]

Best regards
Mateusz

After some time probably I found working solution with all problems even with aapt2 on windows. I have to collect all information to share with you.
Best regards
Mateusz

Happy to hear, and can’t wait to see what you did (no rush, as I;m still traveling anyways).

Hi,
On Windows we have some problems :
1.Using aapt or appt2 (neveer mind) Gradle dependencies is not working properly - I added reference for appcompat and for material and gradle logic downloaded many more aar than the same apk created in Android Studio (after that app crashed after start)
I took all references from Android studio downloaded these needed aar added to my project reference from disk and app is working without crash . I checked references for appcompat 1.2 and there were many unnecessary references whose crashed my app added by ebuild gradle logic.
My app stared working properly with appcompatactivity and aapt
2.UseAppt2 on windows is not working for even simple app without any third party references, problem is during linking resources :

C:\Users\mateu\AppData\Local\Android\Sdk\build-tools\30.0.3\aapt2.exe link -v -o “C:\Users\mateu\AppData\Local\RemObjects Software\EBuild\Obj\2B8AFF02BF332D08A58D2FF897AB2E4A8F3F8995\Debug\Cooper-Android\LinkedResources.apk” --manifest “C:\Users\mateu\AppData\Local\RemObjects Software\EBuild\Obj\2B8AFF02BF332D08A58D2FF897AB2E4A8F3F8995\Debug\Cooper-Android\AndroidManifest.xml” --java “C:\Users\mateu\AppData\Local\RemObjects Software\EBuild\Obj\2B8AFF02BF332D08A58D2FF897AB2E4A8F3F8995\Debug\Cooper-Android\java” -I C:\Users\mateu\AppData\Local\Android\Sdk\platforms\android-33\android.jar --min-sdk-version 26 -R “@C:\Users\mateu\AppData\Local\RemObjects Software\EBuild\Obj\2B8AFF02BF332D08A58D2FF897AB2E4A8F3F8995\Debug\Cooper-Android\Aapt2LinkFiles.txt”

Problem is here -R “@C:\Users\mateu\AppData\Local\RemObjects Software\EBuild\Obj\2B8AFF02BF332D08A58D2FF897AB2E4A8F3F8995\Debug\Cooper-Android\Aapt2LinkFiles.txt”
As i know you can’t call any other type files .flat
Documentation

-R file Passes an individual .flat file to link, using overlay semantics without using the <add-resource> tag.
When you a provide a resource file that overlays an existing file, the last conflicting resource given is used.

I tried this way (this is of course simple example):
1.Compiling resources
aapt2 compile --dir resfolder -o compiled_res/resources.zip
2.Linking
aapt2 link compiled_res/resources.zip -I android_sdk.jar --auto-add-overlay --manifest AndroidManifest.xml --java gen -o out\res.apk
3.Copying dex files to res.apk ( I have no idea how to compile properly from command line my sources and dex them- (I have luck because main R.java identifiiers was the same)
4.Zip align
zipalign.exe -v -p 4 c:\temp\apk3\out\res.apk c:\temp\apk3\out\res_aligned.apk
5.Sign
apksigner sign --ks CertyfikatCS.jks --min-sdk-version 26 --out c:\temp\apk3\out\res_signed.apk c:\temp\apk3\out\res_aligned.apk
The output apk installed and ran properly.
So the first problem on windows with this simple app is linking resources (you entered file with list of files to linking but this file with -R is not recognized) - using .zip or file one by one you can link these resources and the process can go further

In this step I need your help and workaround to link these resources (maybe you link this using .zip or file one by one .
I played with it with appcompatactivity dependencies from commandline and compiled all resources searching in aar and linking using --dir and .zip options but because I don’t know process of compiling my sources and cretaing dex I can’t check if all works properly - here I don’t have luck because as you know after linking resources R.java is created and I can’t copy ready to use dex from ebuid process because identifiers are different in R.java.

Can you make not efficient but working workaround to run this process maybe using .zip or file one by one - because I can’t check what is going on later. I need this for further investigation or maybe you can give me info how to build sources, process aar (third party) and generate dex files ???

I will run this app with third party libraries but only with your help and give you more info for complex app.

On the Fire (Mac OS) simple app is working but more complex is not working too (I didn’t find in logcat useful info - so I want to run this process on windows and check if it works). As you remmeber this app with appcompatactivity references is working with appt after removing not properly added references by ebuild process.

If you help me I think together we will run this process.

I played with

https://musteresel.github.io/posts/2019/07/build-android-app-bundle-on-command-line.html

Best regards
Mateusz

Thanx. will have a detailed look on Thursday when I’m fully back in office.

@mh
on MAC with FIRE
I think you have bug in your AAPT2 with every dependency - I don’t know where is the problem exactly but every dependency gave me error like :

Failed resolution of: Lcom/budiyev/android/codescanner/R$drawable;

For appcompat there is the same error bu starting with appcomat. I think that problem is something in resources or their identifiers (I looked into your log as I know steps are ok but the results is not).

1.I did for investigation simple app with one simpe dependency (com.budiyev.android:code-scanner) and only use main control (code scanner) and in Fire with aapt2 is not working
When I used this library before aapt2 I ran it without any problems (Compiled in old manner in old Rems it works) - I will add all my example at the end of this post.
2.I did the same simple app with the same layout in Android Studio and this one works properly too
3.I compiled and ran the same app from point 1 in old remobjects using aapt and works fine too.
We still talking about problems with dependency (any dependency) and I think resources compiled in new way.
I found in documentation something like this

Incorrect configuration of libraries

If your app has a dependency on a third-party library that was built using older versions of the Android SDK Build Tools, your app might crash at runtime without displaying any errors or warnings. This crash might occur because during the library’s creation, the R.java fields are declared final. As a result, all the resource IDs are inlined in the library’s classes.

AAPT2 relies on being able to re-assign IDs to library resources when building your app. If the library assumes the IDs are final and inlines them in the library DEX, there is a runtime mismatch.

To resolve this error, contact the library author to rebuild the library using the latest version of the Android SDK Build Tools, and republish the library.

but I have no idea how it can affect on your toolchain.
I think that we have problems here with R.java identifiers or something around that.
I wanted to find out how AS building it step by step but I can’t find it…I don’t know where this intermediate process is logged.

Summary : after 4 weeks of fight only one thing I can say Android Platform is not working in Remobjects after aapt2 but as I red Xamarin is working with aapt2 and I checked Android Studio is working too so the problem is inside toolchain.
You have to run this simple dependency (is simple because have only 5 resources files , maybe 6).
When you compile resources you did flat file for res/values but inside app the related values are not to merged in res folder - is it by design ?
Marc maybe the problem is simple but you have to spend time on it and try to run this simple app from attachment on Mac in Fire (because as I saw you did steps in good order but …it doesn’t work - we have to search around identifiers but only you have knowledge about compiling, dexing and using R.Java inside.

One difference I see for older aapt tools for lib you generated seperate R.java and one R.java for apk, now using aapt2 you did one for all.
Second difference in apk res/folder for this simple app is that drawable-hdpi which is in source and has one png is copied into drawable-hdpi-4 but Android Studio keeps folders consistent.

Attachments :
inprax.pl.testapp.zip (631.3 KB)

Fire app with this one dependency (working without aapt2 on Windows in older version, not working in Fire on MAC - crashed after start with

Failed resolution of: Lcom/budiyev/android/codescanner/R$drawable;
There is no difference if I use in this simple example gradle or local aar whose are in folder aar.

Android Studio working app with this one dependency and the same view
MyApplication3.zip (1.6 MB)

I’m sure that you can solve this error in short time because you have knowledge about toolchain - if you will not do it in short time I will have to leave your tools because now simple testcase is not working and when google will change something in future I will probably spend time on it again (without success).
Next week I have to migrate to AS with my apps if you will not run it , but I don’t want it - its time for you to solve this.
I love your tools but now ANDROID PLATFORM IS DEAD but I need it as well as .NET Core and IOS.
Hope for a quick solution to the problem.
I use all the knowledge I have gained so far

Update
Look into in linking resources (maybe something here will be helpfull)
--non-final-ids Generates R.java with non-final resource IDs. References to the IDs from app’s code aren’t inlined during kotlinc or javac compilation.

Best regards, tired aapt2 with dependency
Mateusz

Hmm. c a you send me the list of aars that you get with Elements vs AS, so I can compare? maybe we do dependencies wrong/too broadly, somehow…

Marc i cen send you but know i gave you simpler examlple above with one dependency and few resources… Can we try run this one?? I think that when you run this example with simple dependency we will run appcompat too…
Can you try?

I’d appreciate iof you can send me the list. I cannot get anything to build in Android Studio are, for some reason.

I hate this toolchain so much…

Ok but in this testcase you have simple fire sln which doesnt work with aapt2… All. My testcase are compared to As but please try with this simple testcase in fire… One dependency 3 aar…
Is it working?

This none now gives me

E: Multiple declarations of type “com.budiyev.android.codescanner.R” exist but the partial modifier is missing [/Users/mh/Library/Application Support/RemObjects Software/EBuild/Obj/inprax.pl.testapp-A54B68B8209F14C4E8956123A7E1DC17A5D4F8A2/Debug/Cooper-Android/aar/code-scanner-2.1.0/R.java (5)] // E31 Multiple declarations of type “com.budiyev.android.codescanner.R” exist but the partial modifier is missing

I’ll check, why. Looks like a side effect of may fix, but one I thought I had accounted for.

hmm, curious:

// Auto-generated by EBuild from code-scanner-2.1.0

package com.budiyev.android.codescanner;

public __partial static class R { // E31 Multiple declarations of type "com.budiyev.android.codescanner.R" exist but the partial modifier is missing

and

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.budiyev.android.codescanner;

public final class R { // N1 Previous declaration was here

the first one is created by my fix. The second one seems to be generated by aapt2. That’s the part that was not happening before, which is why I added the fix. So it seems aap2 generates R.java for some files, but not all.

I’m this close to giving up.

Oh wait, your project is set t use Aapt1. Which will not work.

I had to adjust my earlier fix to not run when using Aapt1 (the option for which I had enabled again, earlier today). You project builds ok for me with Aapt2, and (after my fix) with Aapt1.

I did have to disable generating .apk (latest SDK no loge has the tools for that). Also note that you cannot build an .aab when using Aapt1, as that path doesn’t generate the necessary input files for that (I improved the error handling for that today, should be in the build you have).