Android Kinvey java.lang.NoClassDefFoundError - java

I have an android application that used kinvey and it worked just fine with me suddenly i got
java.lang.OutOfMemoryError: GC overhead limit exceeded
so i put
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
in my gradle file but then i got java.lang.NoClassDefFoundError in the line when i create new client
mKinveyClient = new Client.Builder(AP_ID,App_Secret, this).build();
i tried to clean project ,clean gradle file , updated my kinvey sdk from 1.5 to 1.6 Any suggestions?
here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
dexOptions { //for the error java.lang.OutOfMemoryError: GC overhead limit exceeded
incremental true
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.example.dell.augmentedreality"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile files('src/main/java/Vuforia.jar')
compile(name:'kinvey-android-2.10.6', ext:'aar') {changing= true}
compile 'com.android.support:multidex:1.0.0'
compile 'com.gordonwong:material-sheet-fab:1.2.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
///////////////////////////for animating the text
///////////////////////
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
///////////////google cloud messaging
compile 'com.google.android.gms:play-services:8.4.0'
}
Edit:in the image below my jars files

I think the problem is that you copied both the kinvey JAR file and the AAR file into the libs/ folder. You only need the AAR.
The class that is claimed to be missing, com.google.api.client.json.JsonObjectParser, is contained within google-http-client-1.19-0.jar, so adding that JAR file to the correct libs/ directory in the module and including these lines in you build.gradle should properly find that class without error.
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name:'kinvey-android-*', ext:'aar')
// other stuff
}
With regards to the OutOfMemory error, you most likely exceeded the Android Dex method limit because of how many dependencies you've included. Most specifically, the last line of your gradle file for the play-services dependency. If you read that documentation, you'll see the note that says
Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them.
Since you seem to only want cloud messaging, you can just include that one, so replace this line.
compile 'com.google.android.gms:play-services:8.4.0'
With this one
compile 'com.google.android.gms:play-services-gcm:8.4.0'
And any other Play Services you want to include.

i got java.lang.NoClassDefFoundError
You have included wrong Dependant jar. Add appropriate Dependant version of jar by using maven or gradle.

Related

Error: more than one library with package name 'com.google.android.gms.license'

Today, I opened Android Studio, then I get this error. Yesterday, there was a no problem such that!
Error:Execution failed for task ':app:processDebugResources'.
Error: more than one library with package name 'com.google.android.gms.license'
com.google.android.gms:play-services-xxx libraries was
11.8.0
Onesignal library was
'com.onesignal:OneSignal:[3.6.2, 3.99.99]'
Then I changed them to latest version.
Now App/Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "xxx.xxx.xxx"
minSdkVersion 15
targetSdkVersion 24
versionCode 10
versionName 'x.x.x'
manifestPlaceholders = [onesignal_app_id: "xxxxx-xx-xxx",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "XXX"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
repositories {
maven { url 'https://maven.google.com' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
compile 'com.google.android.gms:play-services-ads:12.0.0'
//compile 'com.google.android.gms:play-services-ads:11.2.2'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
//compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:cardview-v7:27.1.0'
compile 'com.android.support:recyclerview-v7:27.1.0'
compile 'com.android.support:design:27.1.0'
compile 'com.balysv:material-ripple:1.0.2'
compile "com.google.firebase:firebase-messaging:12.0.0"
compile 'com.github.hotchemi:android-rate:1.0.1'
compile 'com.onesignal:OneSignal:[3.7.1, 3.99.99]'
compile 'com.google.android.gms:play-services-analytics:12.0.0'
}
apply plugin: 'com.google.gms.google-services'
Project/Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.1.1'
// classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
But I am still getting same error that stated above. How can I solve this problem? Why did this problem occur Today when there was no problem, yesterday?
This probably because the play services version is not in the range defined for
OneSignal:[3.7.1, 3.99.99] which is (you can see it at this commit):
// Limit upper number (exclusive) to prevent untested versions
static def versionGroupOverrides = [
'com.google.android.gms': '[10.2.1, 11.7.0)',
'com.android.support': '[26.0.0, 27.1.0)'
]
So, try changing the play services version to 11.7.0.
You should try using OneSignal Gradle Plugin which helps make the OneSignal Android SDK compatible with your Android Studio project. Use OneSignal-Gradle-Plugin 0.8.0 for OneSignal:[3.7.1, 3.99.99]

"Failed to resolve: com.android.support:support-v4:26.0.0" and other similar errors on Gradle sync [duplicate]

This question already has answers here:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
(26 answers)
Closed 5 years ago.
I have just created a new Android Studio project for both Android Mobile and wear. The initial gradle build failed because I am getting several errors-
Error: Failed to resolve: com.android.support:support-v4:26.0.0
Error: Failed to resolve: com.android.support:percent:26.0.0
Error: Failed to resolve: com.android.support:recyclerview-v7:26.0.0
Error: Failed to resolve: com.android.support:support-annotations:26.0.0
With each error, I am given the option to Install repository and sync project, but nothing happens when I click on it. I have spent several hours trying to find why I am getting these errors, but I can't find any solutions. Does anybody know how to fix these very frustrating errors? Thank you!
build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (mobile)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.androidweartest"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso- core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
wearApp project(':wear')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:appcompat-v7:26+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.android.support:support-core-utils:26+"
testCompile 'junit:junit:4.12'
}
build.gradle (wear)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.androidweartest"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile "com.android.support:support-core-utils:26+"
}
I am sure that my version of Android Studio is updated, and all support repositories and APIs are installed.
I don't have an Android wear project, but I had the same problem when I wanted to upgrade the Support Library version for an existing project to 26.0.0. Since 26.0.0 the support libraries are available through Google's Maven repository. So I had to add the repository to my build. gradle file.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Check out https://developer.android.com/topic/libraries/support-library/setup.html for more details.
The following worked for me:
In the Application build.gradle considered to add following:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
in the Module build.gradle:
compileSdkVersion 26
buildToolsVersion "26.0.1"
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:support-compat:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-annotations:26.0.1'
compile 'com.android.support:support-vector-drawable:26.0.1'
compile 'com.android.support:animated-vector-drawable:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:percent:26.0.1'
compile 'com.android.support:wear:26.0.1'
compile 'com.google.android.support:wearable:2.0.4'
provided 'com.google.android.wearable:wearable:2.0.4'
}
Either change your build tool version from 26.0.1 to 26.0.0 or you can replace 26.0.0 by 26.+ like below.
compile 'com.android.support:support-v4:26.0.0'
to
compile 'com.android.support:support-v4:26.+"
Do same with all...
Hope it helps.
Happy Coding! ^_^
For now, I fixed this with changing in the wear build.gradle:
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
It seems like the problem is com.google.android.support:wearable:2.0.4. With that, Using 26.0.1 build tools compiles fine. I haven't gone any further with this but it looks like a dependency problem related to a repository although that is really just a guess from the error messages.
Add the following dependencies in your app/build.gradle.
repositories {
maven { url 'https://maven.fabric.io/public' }
maven{url 'https://maven.google.com'}
}
Replace this:
compile 'com.android.support:recyclerview-v7:26.0.0'
With this
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
Do same with all
Update - new version released
compile 'com.android.support:recyclerview-v7:26.1.0'
Add following dependency in your gradle
Replace
compile 'com.android.support:support-v4:26.0.0'
with
compile 'com.android.support:support-v4:25.0.0'
and Replace
compile 'com.android.support:appcompat-v7:26+'
with
compile 'com.android.support:appcompat-v7:25.0.0'
The reason that my project was giving me these errors was because I created the project for Android Platform 26. However, Wear currently doesn't support 26, and it is essential to change the target and compile SDK versions to 25 in the wear module of build.gradle.
Link to Android Developers documentation - https://developer.android.com/training/wearables/apps/creating.html#setting-up-a-phone
build.gradle (wear)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.findmyphone"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
}
apply plugin: 'com.google.gms.google-services'
I only needed to change the compile and target SDK versions to 25 in the wear module. I left them as 26 for the mobile module.
This one worked for me
allprojects {
repositories {
jcenter()
google()
}
}
google() does the magic with the following configuration
Studio version : 3.0 beta 2
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
I meet this problem, changing the build tool/ sdk version didn't work, clearly write compile version didn't work, off line build didn't work.
Finally I just change wearable version, and this problem gone.
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'
to
provided 'com.google.android.wearable:wearable:2.0.2'
compile 'com.google.android.support:wearable:2.0.2'
By the way, I used offline building now because it is really fast when I check this issue.

Android studio jdk finished with non-zero value 2

Ok, i know this topic is in stack overflow already, but i did everything i could, i did the multydex thing in my gradle, i did every answer i tried to get at stackoverflow, now i need really help on this, yesterday i was unable to run my app after 3 hs of trying to resolve this, hope you guys can bring me a hand
here is my app gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "myproject.myname.com.myapp"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.firebase:firebase-storage:9.0.0'
compile 'com.google.firebase:firebase-database:9.0.0'
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.firebaseui:firebase-ui-database:0.4.4'
compile 'com.squareup.picasso:picasso:2.5.2'
}
apply plugin: 'com.google.gms.google-services'
here is my project gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
if i try to add the multidex = true and all the multiplex lines i got this error
Error:Execution failed for task ':app:packageAllReleaseClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzajj.class
im really confused and i cant find the answer since yesterday , if someone can help me i will be so glad, thanks
UPDATE
Ok , it seems the firebase compiles were causing the problem for the java jdk value error
after changing it to version 9.4.0 it worked
Change ffirebase:firebase-storage ,'com.google.firebase:firebase-database:9.0.0','`com.google.firebase:firebase-auth:' version to 9.4.0 rather than 9.0.0
Let me know if this works for you .

How to include JAR dependency into an AAR library

Summary:
I have an AAR file that depends on a JAR file, when I build the AAR project, it doesn't contain the JAR code.
Details:
I have a Java SDK library project that contains code that we use for Java web projects and such, this library is created using Gradle and resides in an internal nexus server (as a JAR).
The goal is to provide an "Android configured" version of this JAR library through an AAR library that multiple Android Applications can use and minimize the effort (and boilerplate code) to implement it. This AAR file is also uploaded to the nexus server to be used by the Android Application projects.
My AAR project includes a gradle dependency for my Java SDK library (the JAR) but when built, the AAR doesn't include any classes from it.
Code:
This is the Java SDK project's gradle file:
apply plugin: 'java'
//noinspection GroovyUnusedAssignment
sourceCompatibility = 1.7
version = '1.1.1'
repositories {
mavenCentral()
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'org.springframework:spring-web:3.1.1.RELEASE'
compile 'com.google.code.gson:gson:2.3'
}
This is the gradle file for my AAR Project, note that I removed the Maven repository declarations to my nexus server from it. I guess it shouldn't matter for the sake of this question.
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "2.2.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile ('com.mycompany:javasdk:1.1.1')
}
This is the gradle file for my Android Project, again I removed the nexus server references:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.mycompany.application1"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile ('com.mycompany:androidsdk:2.2.2#aar')
}
NOTE: I initially solved the issue by adding the JAR in the lib directory of the AAR project, but this is undesired. It makes having a nexus server useless. It would be good that we can just bump the JAR's version number in the AAR project's gradle file and the update happens automatically at compile time.
NOTE2: I tried adding transitive=true to my AAR dependency in the Android Project but it didn't solved anything, the real issue is that when building the AAR project, the JAR project code doesn't get bundled.
You can add this task:
task copyLibs(type: Copy) {
from configurations.compile
into 'libs'
}
Dependencies will be downloaded from your Nexus, but when you need package the library, execute this task first and jar files will be copied and included inside final aar.
By default, AAR does not include any dependencies. Solution mentioned by #Hector should work for gradle plugin < 3.0. For Gradle plugin 3.0+, try custom config as mentioned here.
android { ... }
// Add a new configuration to hold your dependencies
configurations {
myConfig
}
dependencies {
....
myConfig 'com.android.support:appcompat-v7:26.1.0'
myConfig 'com.android.support:support-v4:26.1.0'
...
}
task copyLibs(type: Copy) {
from configurations.myConfig
into "libs"
}
None of the suggestions helped me for Gradle 4.6, so I wasted the whole day inventing my own.
Eventually I found a good Gist and modified it for my version of Gradle:
https://gist.github.com/stepio/824ef073447eb8d8d654f22d73f9f30b
The upper ones didn't work for me in android tools 3.6.2 with Gradle. 5.6.1 . For anyone having the same issue, using https://github.com/kezong/fat-aar-android in the end worked fine for me.

How do I import an external library into Android Studio?

I need to use the commons-codec-1.9.jar from the commons-codec-1.9 library supplied by Apache. I've used this as a library in another project in NetBeans, so I already had the required .jar file that I needed to import. I copied the jar file from the NetBeans project and put it in my app project (app:libs folder) and right-clicked and chose the "Add as library..." option. I added it to my project dependencies as well via File > Project Structure > Dependencies. I created the import for the library in the classes I've written that use the library, and I get no errors and the code builds. However, when I run the app, it breaks and throws a NoSuchMethod exception... even though it is there.
Here are the contents of my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.example.<path_stuff>"
minSdkVersion 17
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/commons-codec-1.9.jar')
}
Here is my settings.gradle
include ':app'
I have also recently been getting a build error after I removed the commons-codec stuff from the libs folder and tried to re-add it. The error says something along the lines of "Build failed: could not find task 'assemble' in project " as if Android Studio thinks this is another project. Can someone please help me understand what is going on here and where I am going wrong?
No such method error details:
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String
Edit: Realized I included the incorrect build.gradle file. Updated settings.gradle to remove the include statement. Included correct build.gradle and NoSuchMethod error.
Remove include ':libs:commons-codec-1.9: from your settings.gradle.
Add compile fileTree(dir: 'libs', include: '*.jar') to your dependencies block in your module's build.gradle file.
android {
...
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will automatically compile any .jar file in your libs folder into your project.

Categories

Resources