Android App compiling problem (possible due to copying from iOS project)

My iOS App was successfully compiled with Xojo 2025r2.1
I copied Controls, Methods, Properties from iOS project to Android project.
The compile process of Android App took plenty of time, about more than 10 minutes.

Error message was:
An internal Android Compiler error occurred.
Please create an Issue (xojo.com/issues) and attach your project (privately, if necessary) so that Xojo can investigate the error.

About one year ago, I found the problem and solved it.
(maybe I modified a small part of some Method)
But I forgot the detail modification, and now I meet the problem again.

Please give me some suggestions to solve the problem.
Thank you!

Can you look in your source control system to see what you changed between your last successful run of your Android project and this current issue? That should give you some clues as to what could have caused the issue.

I find that copying methods and properties from an iOS project to an Android project is generally successful, but I haven’t been copying controls. Sometimes there can be surprising issues with copying methods, though. My most recent example is copying this from iOS:

if explodedTag.LastIndex mod 2 <> 0 then return returnValue

That failed to compile on Android. Changing it to the following did compile:

modResult = explodedTag.LastIndex mod 2
if (modResult <> 0) then return returnValue

I’m not saying that’s going to be the cause of your issue, it’s just an example of a surprising cause of a compiler error that will no doubt be addressed now that Xojo have an example in an Issue.

Hopefully examining the changes you’ve made in your source control system will give you some clues.

Once you found the solution, add comments to where the problem lied for the future.

Yes, it is always a good idea to add comment (either in code or in a text file located in the Project folder (with screen shots, eventually).

Previously I copy all controls from iOS project to Android project.
The compiling process failed.

I tried to copy small amount of partial controls, and found a very tricky thing.
Some labels from iOS project to Android project cause failure of compiling.
I created new Labels in Andoid project instead of copying from iOS project.
The compiling got successful!
But, there were some Labels copied from iOS which did not cause failure.

Another tests:
The Android App crashes, due to the initial value was not set when App first run.
I need to set some variables first before controls were triggerd. And I need to prevent some code of event of controls to run while App open, such as TextChanged in MobileTextField and Pressed in MobileSegmentedButton.

In comparison with Xojo for iOS: almost everything runs smooth. And I do not need to set the initial value by my code.

In current version of Xojo, I spend many time to modify my code for Android App.
I hope the future version of Xojo to make Android App easier.

I can probably shed some light here.

As much as Xojo wants you to think that you can just copy and paste controls, there are some complications.

Part 1: When you copy a control in one project, what gets put on the clipboard is a binary representation of the control. Because there’s no way to know what the destination is going to be, every property and their default values are also included. Now, if you were to paste back into the same type of project, using the very same IDE, everything’s going to work perfectly. However, if the project type changes (or the Xojo version changes a lot) things get a little trickier. You see, the IDE stores the values for all of those properties in a dictionary, and when you paste, that dictionary is just populated with everything from the clipboard. Again, the IDE doesn’t know where the data is coming from.

Part 2: When a project is rendered, prior to compiling, all of the properties currently attached to each control is rendered into an initialization method that is called when a control is first starting up. So if you had a dictionary that looks like this

{
One: 1,
Two: “2”,
Three: True
}

This special hidden initializer might look like this:

Self.One = 1
Self.Two = “2”
Self.Three = True

Since the iOS project is years more mature than Android, there’s bound to be properties that don’t exist on Android that do on iOS, but the IDE doesn’t know that and just dutifully renders all of the properties. This of course causes compile issues because while “Three” existed in an iOS project, it doesn’t on Android, but it may in the future. This retention of properties is actually intentional, and it supports the backward & forward compatibility of the IDE, so it’s not as simple as just stripping them out.

What I suggest is that you follow these steps until the IDE stops making changes. It’ll be easier to track if you’re using version control…

  1. Save the project as text
  2. Close the project
  3. Make a note of any changes
  4. Open the project
  5. In the navigator, select a control on a layout that’s giving you trouble and then make a change of some sort, just pressing left & right keys would be enough. Just something to mark the control as “dirty”
  6. Go to step 1

Repeat this process until the IDE stops making changes and then commit the changes to your version control system.

Note: because that method that initializes the properties only exists during rendering, if a syntax error is encountered, you’ll get a strange error about the problem being in the “name” property of the object. 99.9% of the time you get that compile error, it’s in one of the rendered methods. If you’re really stumped, reach out to Xojo. They can run your project and find out what the offending item is.

2 Likes