Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.5 ExceptionInInitializerError #2

Closed
niqo01 opened this issue Jul 30, 2014 · 20 comments
Closed

v2.0.5 ExceptionInInitializerError #2

niqo01 opened this issue Jul 30, 2014 · 20 comments

Comments

@niqo01
Copy link

niqo01 commented Jul 30, 2014

Version 2.0.5
I am having the following exception while creating a new TransferManager.

Caused by: java.lang.ExceptionInInitializerError
            at com.amazonaws.ServiceNameFactory.getServiceName(Unknown Source)
            at com.amazonaws.AmazonWebServiceClient.computeServiceName(Unknown Source)
            at com.amazonaws.AmazonWebServiceClient.getServiceNameIntern(Unknown Source)
            at com.amazonaws.AmazonWebServiceClient.computeSignerByURI(Unknown Source)
            at com.amazonaws.AmazonWebServiceClient.setEndpoint(Unknown Source)
            at com.amazonaws.services.s3.AmazonS3Client.setEndpoint(Unknown Source)
            at com.amazonaws.services.s3.AmazonS3Client.init(Unknown Source)
            at com.amazonaws.services.s3.AmazonS3Client.<init>(Unknown Source)
            at com.amazonaws.services.s3.AmazonS3Client.<init>(Unknown Source)
            at com.amazonaws.services.s3.transfer.TransferManager.<init>(Unknown Source)

I don't know if its related but there some Dex warning while building the application

warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$3) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$4) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$5) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$6) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
@niqo01
Copy link
Author

niqo01 commented Jul 30, 2014

I just saw this line before the exception:

6293-6293/com.couchsurfing.mobile.debug W/dalvikvm﹕ Exception Ljava/lang/IllegalStateException; thrown while initializing Lcom/amazonaws/internal/config/InternalConfig$Factory;

@niqo01
Copy link
Author

niqo01 commented Jul 30, 2014

I found and solve the issue. aws-android-sdk-2.0.5-core.jar include a file named awssdk_config_default.json which is not a valid json. Removing the "java style" comment solve the issue...

@wdane
Copy link
Contributor

wdane commented Jul 30, 2014

Hey niqo01,

I really appreciate you posting the issue and fix! Would you be able to give us an example of how you were initializing the Transfer Manager. This issue never came up in our testing and I'd like to learn why so we can fix it for our future releases. I'm assuming you were also using version 2.0.5 of S3?

Thanks,
Weston

@niqo01
Copy link
Author

niqo01 commented Jul 30, 2014

Yes, I am also using 2.0.5 of S3 . My test code looks like this

public TransferManager getTransferManager()
    return new TransferManager(  new BasicAWSCredentials( AWS_S3_ACCESS_KEY, AWS_S3_SECRET_ACCESS_KEY ));
  }

The code crashed directly at the TransferManager creation

@richardfung
Copy link
Contributor

Hi, thanks for helping us improve the SDK!

We aren't able to reproduce this issue so it would be awesome if you could provide us with a few more details. Namely,

  1. Version of Android you are compiling against
  2. Whether you are using the core jar which includes or doesn't include third party libraries
  3. Your development environment
  4. Are you compiling in debug/release mode and with or without proguard?

Thanks again!

@niqo01
Copy link
Author

niqo01 commented Aug 5, 2014

  1. SDK version 19
  2. Core jar with third party libraries. Could I just use the one without the third party dependencies ?
  3. Android Studio 0.8.4 / Gradle Android 0.12.2 / Gradle 1.12
  4. debug with proguard

@ma-hussain
Copy link

Hey niqo01,
I am also stuck with the same error since last 2 days.... In one of your above comments I read that you have resolved it.
Sorry but I am unable to understand your solution, can you please clarify a little more ??
If you can show me the updated awssdk_config_default.json file ..... Thanks in advance...

@niqo01
Copy link
Author

niqo01 commented Aug 5, 2014

@ma-hussain The fix which worked for me is to:

  1. Open aws-android-sdk-2.0.5.jar with a zip tool,
  2. Open awssdk_config_default.json file and remove the comments (line starting with //). I recommend to check the result json with a json validator like http://jsonlint.com/
  3. replace the new file in the jar.
  4. Use the new file jar as a dependency.

@ma-hussain
Copy link

@niqo01 I have removed the commented lines but still I am getting errors. Can you explain what was wrong with the comment in awssdk_config_default.json file and why just removing a comment in the file worked for you ??
Below is the error I am getting:

08-06 18:26:31.650: I/VersionInfoUtils(20672): Unable to load version information for the running SDK: /com/amazonaws/sdk/versionInfo.properties not found on classpath
08-06 18:26:31.670: W/dalvikvm(20672): VFY: unable to find class referenced in signature (Lcom/fasterxml/jackson/databind/ObjectMapper;)
08-06 18:26:31.670: I/dalvikvm(20672): Could not find method com.fasterxml.jackson.databind.ObjectMapper.readValue, referenced from method com.amazonaws.internal.config.InternalConfig.loadfrom
08-06 18:26:31.670: W/dalvikvm(20672): VFY: unable to resolve virtual method 18785: Lcom/fasterxml/jackson/databind/ObjectMapper;.readValue (Ljava/net/URL;Ljava/lang/Class;)Ljava/lang/Object;
08-06 18:26:31.670: D/dalvikvm(20672): VFY: replacing opcode 0x6e at 0x000e
08-06 18:26:31.680: W/dalvikvm(20672): Exception Ljava/lang/IllegalArgumentException; thrown while initializing Lcom/amazonaws/internal/config/InternalConfig$Factory;
08-06 18:26:31.690: I/dalvikvm(20672): Rejecting re-init on previously-failed class Lcom/amazonaws/internal/config/InternalConfig$Factory; v=0x0
08-06 18:26:31.690: D/AndroidRuntime(20672): Shutting down VM
08-06 18:26:31.690: W/dalvikvm(20672): threadid=1: thread exiting with uncaught exception (group=0x40a241f8)

E/AndroidRuntime(19831): FATAL EXCEPTION: main
08-06 17:45:08.470: E/AndroidRuntime(19831): java.lang.NoClassDefFoundError: com/amazonaws/internal/config/InternalConfig$Factory
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.ServiceNameFactory.getServiceName(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.AmazonWebServiceClient.computeServiceName(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.AmazonWebServiceClient.getServiceNameIntern(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.AmazonWebServiceClient.computeSignerByURI(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.AmazonWebServiceClient.setEndpoint(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.services.s3.AmazonS3Client.setEndpoint(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.services.s3.AmazonS3Client.init(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.services.s3.AmazonS3Client.(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.services.s3.AmazonS3Client.(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.services.s3.AmazonS3Client.(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.amazonaws.services.s3.transfer.TransferManager.(Unknown Source)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.zahdoo.android.extension.GCM.FileTransferActivity.onCreate(FileTransferActivity.java:77)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.app.Activity.performCreate(Activity.java:4465)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.os.Looper.loop(Looper.java:137)
08-06 17:45:08.470: E/AndroidRuntime(19831): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-06 17:45:08.470: E/AndroidRuntime(19831): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 17:45:08.470: E/AndroidRuntime(19831): at java.lang.reflect.Method.invoke(Method.java:511)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-06 17:45:08.470: E/AndroidRuntime(19831): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-06 17:45:08.470: E/AndroidRuntime(19831): at dalvik.system.NativeStart.main(Native Method)

@niqo01
Copy link
Author

niqo01 commented Aug 6, 2014

@ma-hussain just copy the content of the awssdk_config_default.json in the following json validator website: http://jsonlint.com/ and hit validate.

Also you can read here more about comment in json file: http://stackoverflow.com/questions/244777/can-i-comment-a-json-file

@richardfung
Copy link
Contributor

@ma-hussain If you are using proguard can you post your proguard config? Also we are looking into this json file issue.

@ma-hussain
Copy link

Let me explain my issue properly...

I need to use S3 in my mobile app which is built using Adobe Flex and we are accessing all the native java android feature by creating ActionScript Native Extensions(ANE) which allows me incorporate native platform capabilities into my application and use them like standard libraries..

So, I downloaded the S3 java android sample executed it and it is working fine, I can upload/download my files to/from my S3 bucket. I included aws-android-sdk-2.0.5-s3.jar and aws-android-sdk-2.0.5-core.jar into the libs folder and everything is working fine.

But when I am merging the code with my Java ANE , I am using the the aws-sdk core and s3 jar. It is compiling without any errors, I create the ANE from it and add it to my Flex app but when I run my Flex app ,it is giving me those errors just when initializing TransferManager..

@wdane
Copy link
Contributor

wdane commented Aug 7, 2014

Hey ma-hussain,

We've seen a number of cross-platform development tools strip out non-java files from jars in the past. It looks to me like Flex is stripping these files out of our SDK jars. Can you verify if this is the case, and if so see if Flex provides an options for not stripping out these files?

Thanks,
Weston

@ma-hussain
Copy link

@wdane May be you are correct . But I have not yet come across a solution to stop Flex from stripping the non-java files. I am still working on it.

By the way can you tell me whether any AWS S3 sdk is available for Adobe Flex.
I have found some links ,but they dont have a proper documentation. Can you please check these below:
i.) https://aws.amazon.com/articles/Amazon-S3/2434
ii.) https://code.google.com/p/as3awss3lib/

@wdane
Copy link
Contributor

wdane commented Aug 12, 2014

@ma-hussain Unfortunately we do not currently support Adobe Flex, the AWS article is not specifically targeting mobile developers using our SDK. The second link is not something that has been produced by Amazon so I cannot help in that regard.

However another customer has had a similar issue and has provided detailed steps as to how to get around it. He is using Adobe Air, but the solutions should be relatively universal for cross compilers stripping out non-java files. https://forums.aws.amazon.com/thread.jspa?messageID=562833&#562833

@ma-hussain
Copy link

@wdane Hey Weston ,
After going through the above link you provided and doing some modifications I was finally able to use Amazon AWS S3 from my Adobe Flex app.
The process is a little complex but after the initial hiccups it was done
Thanks a LOT...
I will post the whole process here soon...

@wdane
Copy link
Contributor

wdane commented Aug 20, 2014

@ma-hussain
Really glad to hear you got it working!

@ma-hussain
Copy link

To use Amazon S3 for Adobe Flex/Action Script mobile app using JAVA ANE, follow the following procedure. You must have prior knowledge on how to create ANE(Air Native Extension).

But before going through the below steps I suggest you go through this link
-> https://forums.aws.amazon.com/thread.jspa?messageID=562833#562833.
See the 4th comment .I got it working with the help of that.

1.) First of all copy the 'fasterxml' folder inside the 'com' folder of your ANENative project by using Windows explorer.
Actually I was getting some error related to jackson-core so I downloaded the 'jackson-core-2.1.5.jar' from the following link

-> http://grepcode.com/snapshot/repo1.maven.org/maven2/com.fasterxml.jackson.core/jackson-core/2.1.5  

From this jar I extracted the files which were missing and put it into the 'fasterxml' folder

Here is the link of the 'fasterxml' folder in case you need it.
->https://www.dropbox.com/s/e36n2csvsmyiycs/fasterxml.zip?dl=0

 Directly copy this 'fasterxml' folder inside the 'com' folder of your ANENative project by using Windows explorer not using your IDE.

If you want to reproduce the same error you can skip this step. This will help you understand the reason I needed this 'fasterxml' folder.

2.)After your java android ANENative project is ready with all the S3 code with the 'aws-android-sdk-2.0.5-core.jar' and 'aws-android-sdk-2.0.5-s3.jar' inside the libs folder, export your ANENative project to a jar file say ANENative.jar .

3.)After step 2, we need to extract 'aws-android-sdk-2.0.5-core.jar' and 'aws-android-sdk-2.0.5-s3.jar' into 2 different folders.

If you dont have the above jar files, download it from this link - > 'http://aws.amazon.com/sdk-for-android/'

copy the ANENative.jar file to the folder containing the extracted "aws-android-sdk-2.0.5-core" package and files from 'aws-android-sdk-2.0.5-core.jar' library and run the following commands

i.)jar -uf ANENative.jar com  
ii.)jar -uf ANENative.jar org   
iii.)jar -uf ANENative.jar META-INF
iv.)jar -uf ANENative.jar awssdk_config_default.json
v.)jar -uf ANENative.jar mime.types

Note:Here merging 'javax' folder is not necessary as it is empty

3.) copy the modified ANENative.jar file to the folder containing the extracted "aws-android-sdk-2.0.5-s3" package and files from 'aws-android-sdk-2.0.5-s3.jar' library and run the following commands

i.)jar -uf ANENative.jar com 

Note:Here merging 'META-INF' is not necessary   

4.)Now use this 'ANENative.jar' to create the ANE.

5.)Add the created ANE to build path Native Extensions of your Adobe Flex mobile project.

6.)Export the release build using the regular technique by Adobe Flash Builder to get the .apk file

7.)IMPORTANT: Now from the extracted folders of the 'aws-android-sdk-2.0.5-core.jar' and 'aws-android-sdk-2.0.5-s3.jar' file remove all the non-class files and keep the remaining files in another seperate folder with the package structure intact.

Here is the link of the extracted jar without the class files in case you need it.(Otherwise it takes a lot of time to manually find and remove all the class files)
https://www.dropbox.com/s/bqevt7d4et1opv2/AWS_LIBS_NO_CLASS.zip?dl=0

i.)This folder should contain 'com' folder, 'org' folder , awssdk_config_default.json file and mime.types file.
ii.) copy the generated .apk  file in the above folder.
iii.) Open the .apk file with WINRAR, on the top right you will see an 'Add' icon.
iv.) Add one by one all the four items in this apk.('com' folder, 'org' folder , awssdk_config_default.json file and mime.types 

file)

Note:Step iv) is alternative to 'aapt add ANENative.jar <path to file> '.  As we have to run this command to many files 

therefore opted to add them using WINRAR as described in Step iv

8.)Remove the previous signing bits, 'aapt remove ' for CERT.RSA, 'CERT.SF, MANIFEST.MF in META-INF

i.)aapt remove <apk> META-INF/MANIFEST.MF
ii.)aapt remove <apk> META-INF/CERT.RSA
iii.)aapt remove <apk> META-INF/CERT.SF

9.) Resign the apk with 'jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore '

10.)Realign the apk with zipalign 'zipalign -v 4 <apk_prealign> '

NOW WE ARE DONE. Install the apk and Amazon S3 should work now

Hope this may help someone who needs to use Amazon S3 using Flex mobile app

@wdane
Copy link
Contributor

wdane commented Sep 19, 2014

Would like to thank everyone for contributing all of their experiences and help. Closing the issue, as it seems like solid work-arounds have been found though we will be looking into making this easier in the future.

@wdane wdane closed this as completed Sep 19, 2014
@mtrewartha
Copy link

We actually still get this error in a native Android app, even when ProGuard is disabled, using 2.1.7. Have you guys seen any more issues crop up with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants