简体   繁体   中英

CodenameOne - Inner class causes dex build errors

I am building my CodenameOne app on their server. It is the Android build. I already fixed some build issues.

Now I am facing an issue that seems to depend on my source code:

I have a 'R' class with a 'string' class inside. It is to get string constants for localization utiity methods with key/value pairs:

String translatedString=StringRes.getStringByKey(R.string.string_key);

it is the usage, the gist of translation is hidden in the method, and leverages CodenameOne way of doing it. I know mine is different from their approach but it works very well for me, and it is similar and fairly compatible with the Android version of my app.

The class is something like:

public class R {
public static Command myCommand=new Command(StringRes.getStringByKey(string.myCommand));
...
...
public static class string
{
...
...
...

In the build I get errors regarding it:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':transformDexArchiveWithDexMergerForDebug'.

java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/myapp/app/R$string;

com.android.build.api.transform.TransformException: com.android.dex.DexException:: Multiple dex files define Lcom/myapp/app/R$string; 

com.android.dex.DexException: Multiple dex files define Lcom/myapp/app/R$string; 

What is this?

And how to fix it?

I think what fails is the R class which is a special case on Android. I would suggest naming your class differently to avoid a collision with the native android R class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM