Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

java - 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?

question from:https://stackoverflow.com/questions/65916687/codenameone-inner-class-causes-dex-build-errors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...