Android No expanded opcode for R.java - android

I have an important problem while compiling Android Application.
Using Windev Mobile, it generates java code, compile and create apk, however, when the apk creation, an error happens:
command line: "myjavapath\java.exe" -Xmx1024m -Djava.ext.dirs=.\platform-tools\lib -jar .\platform-tools\lib\dx.jar --dex --output "path\classes.dex" "path\classes" "path\libs"
returned error:
Trouble writing output: No expanded opcode for 0004368d R.java:11#0001: invoke-direct v0:NffffLmynamespace/R$attr;, java.lang.Object.<init>:()v
Furthermore, R$attr in R.java contains nothing:
public static final class attr {
}
I assume there is a hard limit of 64k. But:
The R.java file contains only 364 lines, if these lines are
fields/methods references, I'm very far away from 64k hard limit.
This error happened when I add a specific window, in my Windev Mobile project. Window that I'm using in another project without error.
So, what do you think it comes from?
If you need any information, or document, no problem.
Thanks in advance.
PS: Maybe my english isn't perfect, I sorry for that.

There are various limits in the dex file format. It looks like the one you are encountering is that there can't be more than 64k method references. This limit is for all classes in your dex file, not for just a single class.
The fact that the error is occurring on that class has nothing to do with the class itself, that's just that where it happened to hit the limit.
The only solution currently, is to reduce the size of your code, or to split some classes out into a separate dex file that you load dynamically.

Related

What is the exact meaning of "Too many field references" in Android?

I can check the classes.dex file through analyze apk in Android studio.
For example.
This dex file defines 9214 clasees with 48592 methods, and references 57284 methods.
If the build fails because of a dex error, I will see the following error message.
Too many field references: 70000; max is 65536.
You may try using --multi-dex option.
What exactly does 70000 mean in this error message?
Number of defined method? or Number of referenced Methods?
If the answer is a number of methods, is it possible to do the following result?
This dex file defines 9214 clasees with 60000 methods, and references 70000 methods.
I've already read sentence below.
The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536
(from Document)
But I don't know exactly what 65536 means.
Please tell me the answer. THX :)
You have to enable multidex for your application.
Refer: https://developer.android.com/studio/build/multidex
Guide: How to enable multidexing with the new Android Multidex support library
What exactly does 70000 mean in this error message?
Ans: Total methods count in your apk(includes methods count from libraries also).

BouncyCastle Error

I am developing an android application. In this application I create my own private key by passing pass phrase, user id and keys. When creating the private key, it says "Error: org.bouncycastle.openpgp.PGPException: cannot create cipher: CAST5/CFB/NoPadding"
I have checked the logcat as well as the warning section in the Eclipse but there is error there. SO why I am getting this error and how to solve it.
Any help is greatly appreciated!
I am using bcpg-jdk15on-150.jar and bcprov-jdk15on-150.jar,
which I have downloaded from http://www.bouncycastle.org/latest_releases.html
EDIT
the solution of renaming one or both the jar files does not work. When I run the application it says Unable to execute dex: Multiple dex files define Lorg/bouncycastle/apache/bzip2/BZip2Constants;
and Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/bouncycastle/apache/bzip2/BZip2Constants;
I think there is a problem with the duplication of some files within the two jar files. Can anyone suggest me a solution regarding this?
Thanks
Use latest BouncyCastle and setup security in your code in the following way:
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
Security.insertProviderAt(new BouncyCastleProvider(), 1);
It sets Bouncy Castle library as preferred security provider; Android's default provider config has BC at position 3 so this code will remove it and insert BC again at position 1.
It solved the problem for me.

"trouble writing output: Too many field references: 70185; max is 65536. You may try using --multi-dex option." when building Android project

I hit this error and found no hits for the error message, so I thought I'd share the solution I came up with to save anyone else facing the problem repeating my work.
When writing a new Android library (apklib) for use in a (large) application, I'm getting the following error during dexing when I add my new project as a dependency:
trouble writing output: Too many field references: 70185; max is 65536.
You may try using --multi-dex option.
References by package:
<...long list of packages with field counts elided...>
The particular build step it fails on is:
java -jar $ANDROID_SDK/build-tools/19.0.3/lib/dx.jar --dex \
--output=$PROJECT_HOME/target/classes.dex \
<... long list of apklib and jar dependencies elided ...>
Using --multi-dex as recommended by the error message might be a solution, but I'm not the owner of the application project and it already has a large complex build process that I would hesitate to change regardless.
I can reproduce this problem with a no-op test library project that has literally no fields, but in the error output it's listed as having 6000+ fields. Of the packages listed in the error output, there are a handful with similar 6k+ field counts, but then the vast majority have more plausible <1k field counts.
This problem is similar to the "Too many methods" problem that Facebook famously hacked their way around. The FB solution seems insane, and the only other solutions I've found (e.g., this Android bug ticket, or this one, this SO answer, this other SO answer) all involve changing the main app's code which is well beyond the scope of what I want to do.
Is there any other solution?
The solution was to change the package in the AndroidManifest to match the main application's package.
A manifest like this:
<manifest package="com.example.testlibrary" ...
resulted in 6k+ fields and build failure. Changing it to match the main application's package
<manifest package="com.example.mainapplication" ...
resulted in the project building successfully.
Note that only the package in the manifest is changing, I did not make any changes to the library's Java source or its layout (the Java package was still com.example.testlibrary with directory structure to match).
I hypothesize that the different package name is causing all the Android fields to be included again under that package. All the packages in the error listing with 6k+ fields had a different package name than the main application.
I also (later, grr), found this blog post which details the same problem and the eventual same solution.

Code Coverage on Android

I know that there are many questions that have been asked about Android code coverage (I have done some researches before asking here), yet I still get stuck at some points so if you can help, I will appreciate it very much.
What I am doing right now is not really Unit Test but Activity Test to verify the views (check whether they're null or not, check the buttons if they're clickable, counts the number of view in one activity), then I implement some code to test public methods of each activity too and I want to know the code coverage of those tests. First I try EclEmma but it seems like they don't support android so I move to Emma. Then I have a common error as many many people on the Internet:
[exec] android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests:INSTRUMENTATION_RESULT: shortMsg=java.lang.IllegalAccessError
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.IllegalAccessError: Classref in pre-verified class resolved to unexpected implementation
[exec] INSTRUMENTATION_CODE: 0
[echo] Setting permission to download the coverage file...
[exec] Unable to chmod /data/coverage.ec: No such file or directory
[echo] Downloading coverage file into project directory...
[exec] remote object '/data/coverage.ec' does not exist
I tried many things that other people do but they just can't fix my issues. I changed from data/data/coverage.ec to sdcard/coverage.ec and now is data/coverage.ec, none of them works. I tried to mount -o remount rw /sdcard, that doesn't work too.
Is there any other ways to fix this? Are Activity Tests even test-able? or I have to change to something other than Emma?
My bad, at first I followed a site (I don't remember) to copy emma.jar into my test project /libs/. I think it somehow calls the jar file twice so it throws IllegalAccessError . I solve this problem by deleting all emma, emma_ant jar files and copy them into /Java/jdk/jre/lib/ext. Now all of my tests run fine and I can get the code coverage now.

XMLVM Android to iPhone Errors

The conversion of my Android application to the iPhone ObjectX environment as described in the XMLVM user manual works almost fine on my MAC, but I end up with 3 errors in the resulting XCode:
The first two errors simply relate to missing files, namely:
org_w3c_dom_Node.h
android_app_DatePickerDialog_OnDateSetListener.h
These are clearly not files from the converted Android application. Where can I get these from?
The third is an error that keeps coming up in the file
java_lang_String.h
The error message is:
typedef NSMutableString java_lang_String: redefinition as different kind of symbol
This error has been reported before in the XMLVM user group but as far as I know has never been answered sufficiently.
About the first error:
this is part of the Android API that has not yet been implemented.
This is the reason why it can't find the files.
Now, the second problem is not actually an error, but a warning and shouldn't stop you form compiling.
If it does, it means that in your project you have set the option to make errors from these types of warnings.
You can safely turn this off and completely ignore this warning.

Categories

Resources