0

I've been trying to fix this problem for an entire day, and it's probably just something ridiculous. I'm running Android Studio 0.2.5. I needed a library to work on my application (GrepCode internal stuff), so I went and downloaded the jar file and the jar files it depends on. I followed instructions from other SO answers on how to include these dependencies into my project and now I'm getting an error.

1) I first added the jars to the 'libs' folder that I created in the Module

2) I right clicked and hit Add to Library..., named the Library, tried adding it at different levels and still get this error.

3) I went into the Modules section of the settings and made sure that library was selected under the Dependencies tab.

4) I run gradlew clean in the Project directory.

Now at this point, if I don't do step 5 here, I simply get an error saying the packages I'm trying to import don't exist, even though the IDE doesn't SHOW an error when typing out the import statements or the classes from the libraries. Because of this, I tried step 5. According to all the guides, what I did up to this point should have worked.

5) In my build.gradle, the dependencies did not show up, so I typed them out and now this is what my dependency section looks like. If I do not type these out, I just get an error that says the packages don't exist when I try to import them.

dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile files('libs/openjdk-6-b14.jar')
compile files('libs/junit-3.8.1.jar')
compile files('libs/logkit-1.0.1.jar')
compile files('libs/servlet-api-2.3.jar')
compile files('libs/httpcore-4.0.1.jar')
compile files('libs/commons-codec-1.3.jar')
compile files('libs/commons-logging.jar')
compile files('libs/httpclient-4.0.1.jar')
compile files('libs/json-20080701.jar')
compile files('libs/opengl-api-gl1.1-android-2.1_r1.jar')
compile files('libs/xpp3-1.1.4c.jar')
compile files('libs/android-4.2.2_r1.jar')
}

After this I get an error in the message box saying "Gradle: Execution failed for task ':SendPicTest:dexDebug'."

And in the idea.log I find this error: "java.lang.OutOfMemoryError: GC overhead limit exceeded"

So, I believe Step 5 is unnecessary, but I'm not sure. I've tried many different ways of importing these libraries and NOTHING has worked...I'm completed lost...anybody have any ideas? Thanks!

datWooWoo
  • 843
  • 1
  • 12
  • 42

1 Answers1

0

EDIT

After looking at your dependencies list, it seems obvious that the problem is there. I suggest you to try to:

1) understand why you choose to include each of those libs.

2) understand the android architecture and build process. (maybe read this)

Here are a few remarks:

  • openjdk-6-b14.jar MUST be removed. You are developing an Android app and so it will run against the Android SDK. The Android SDK already define most of the classes of the openjdk (so you will have conflicts when dexing this jar). Additionally lot of classes in this jar are simply not dexable (like javax.swing.*) because they use unsupported features and don't make sence on Android.

  • android-4.2.2_r1.jar is a stub jar (look at the code: all methods throw an exception). This artifact is only usable the build your android code with a standard javac compiler (and so producing *.class file). After that, all your *.class will be dexed (i.e. transformed into *.dex files) by android compiler. At runtime, the real android-api implementation will be used (instead of this artifact).

  • servlet-api : it's very uncommon to need this in an android-app. It only define an API (without implementation). The implementation is usually provided by the application server (tomcat, jboss,...) in standard J2EE developement. Android-sdk don't provide an implementation for this API.

  • junit : usually a dependency with scope test.

  • httpcore (and probably also httpclient) : a common mistake on android. An old implementation of this library is included in the android-sdk. If you keep it, you will have a top-level exception while building your app (this exception means that you try to override a class from the android-sdk : this is not possible)

  • opengl-api-gl1.1-android-2.1_r1.jar : I don't know exactly what it contains, but I guess the same remark as what I wrote about android-4.2.2_r1.jar applies here.

END EDIT

So, I believe Step 5 is unnecessary

No step 5 is necessary ! The build.gradle is where dependencies are defined... so if AndroidStudio don't update this file for you : do it by hand.

After that, you may need to reimport the project from gradle files (find the reimport button on top of the gradle view on the right edge of the window)

Regarding the error in the log file:

You can increase AndroidStudio memory settings from this file:

<ANDROID_STUDIO_INSTALL_DIR>/bin/studio.exe.vmoptions

or

<ANDROID_STUDIO_INSTALL_DIR>/bin/studio64.exe.vmoptions

if you run 64 bits version.

I suggest you to try to change the settings to avoid the "java.lang.OutOfMemoryError: GC overhead limit exceeded"

This error means that GC is running very long (98% of the time) and less than 2% of the heap is released. So you can try to increase the heap (and restart AndroidStudio):

-Xmx1024m

Another option, is to disable this check by adding this line in the *.vmoptions file:

-XX:-UseGCOverheadLimit

(note that since it is not a standard JVM args: it may not be supported by your JVM) Anyway I don't recommend this option, since the GC will run for a while with very poor results and your IDE will be very very unresponsive.

I also suggest you to read this regarding usage of AndroidStudio today.

Community
  • 1
  • 1
ben75
  • 29,217
  • 10
  • 88
  • 134
  • So I tried both increasing the heap and trying disabling the check...no luck. Again the "Java Heap Memory" runs out and it gets an error. I don't understand why it takes over 2 minutes+ to compile after I add those to the build.gradle. Is the above way I did it incorrect or something? I don't think it should be taking that long. This is so ridiculously discouraging...I should have stuck to Eclipse... – datWooWoo Aug 28 '13 at 23:56
  • Don't be surprised to find bugs in a software that isn't released yet. – ben75 Aug 29 '13 at 05:41
  • ... I just take a close look at the dependencies you have. They are wrong ! remove this one : 'libs/android-4.2.2_r1.jar' and this one òpen-jdk`. And I'm very suspicious about this one : `opengl-api-gl1.1-android-2.1_r1.jar`. The problem is comming from your dependencies for sure. (I found strange to have servlet-api and junit too) – ben75 Aug 29 '13 at 05:48