Android Ormlite: java.lang.NoClassDefFoundError - android

I am using ormlite in an Android project from Android Studio. I have configured Gradle to use it from Maven, like so:
dependencies {
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
However, when I launch the app it's giving NoClassDefFoundError for all ormlite classes. The same works if it is done by copying the jars to "libs/" folder.
Any idea why adding them from Maven doesn't work?

Try this on build.gradle:
dependencies {
compile 'com.j256.ormlite:ormlite-android:4.48'
...
}
The ormlite-core is a dependency that gradle will resolve by it's self. After editing, sync and rebuild you app, it should work.
If you want to put jar files in you libs folder, than your dependecies line from build.gradle will look like this:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
...
}

Related

How to declare the dependencies of a library project when those dependencies should be fulfilled by the consuming application?

I'm developing an android library that depends on some third party aars and jars.
Currently, these dependencies are declared in the library module's gradle buildscript like so:
repositories {
flatDir{
dirs 'libs', 'android-libs'
}
}
dependencies{
compile(name: 'threetenabp-1.0.5', ext: 'aar')
compile fileTree(include: ['*.jar'], dir: 'libs')
}
However, this results in the dependencies' classes being built into the aar, potentially causing conflicts when the library is used in an application.
How can I reference these dependencies from my library without actually packaging them into the library?
I have tried changing the declarations from "compile" to "provided" and then compiling the files into the application, but when I do this my library fails to build.
After some reading at https://docs.gradle.org/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies I eventually figured out that using compile fileTree will package the dependencies into the output library. To avoid this, declare each dependency individually, using the following syntax:
dependencies {
compile: name: 'filename-without-extension'
}
And the dependencies will no longer be packaged into the output.
The project making use of the output aar will still need to include the flat-dir repository that holds the jar files, like so:
repositories {
flatDir{
dirs 'libs'
}
}

Resolve Gradle Dependency into local JAR in Android Studio

Currently, my Android app project compiles against a local library project like so:
// build.gradle
dependencies {
compile project(':Library-Project')
compile files('libs/library.jar') // Resolve into this if Library-Project is not available
}
The local library project builds into library.jar and is placed in the libs folder.
Is there a way to fallback on the library.jar artifact if the local project is not present without commenting compile project(':Library-Project') in lieu of compiling against the jar?
Used a more dynamic approach for which dependency should actually get compiled.
dependencies {
// Check if the local project exists, and compile against that if it does
if ( new File("/Library-Project").exists() )
{
compile project(':Library-Project')
}
// Local project DNE, compile against JAR file
else
{
compile files('libs/library.jar')
}
}
Another way to automatically compile all JAR files in the /libs folder is by adding the following line within your dependencies block:
compile fileTree(include: ['*.jar'], dir: 'libs')

Adding itextg to gradle

I want to add itextg via gradle to avoid having to maintain a set of library jars. Maybe it's me but I can't find the correct gradle compile statement anywhere.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.itextg:itextg:5.4.3'
}
Regular itext works just fine but I'm trying to do stuff with images.
compile 'com.itextpdf:itextpdf-5.5.6'
I think that's because we released iText as a jar on Maven Central (which Gradle also uses as a repository) and also as a download from various sites (GitHub, SourceForge); but iTextG only as a download on various sites, not on Maven Central. iTextG uses the same namespace as iText: com.itextpdf:itextpdf so having it on Maven Central too would create conflicts. Something like com.itextg:itextg simply does not exist (as far as I know - and I am supposed to know because I am QA Engineer at iText Software).
In fact, the main difference between iText and iTextG, is that we have stripped all AWT dependencies from iTextG. For the rest they are exactly the same codebase.
So, to finally answer your question after all this background information: you'll have to download the iTextG jar and manually add it to your libs folder.
As of iText 5.5.9, you can add this to your Gradle file:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.itextpdf:itextg:5.5.9'
}

android design library gradle null pointer exception

I'm trying to add android.support.design library to my project: All the interesting things in my gradle file:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:support-annotations:22.0.0'
compile 'com.android.support:support-v13:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:cardview-v7:22.1.0'
}
I'm getting
Error:Android Gradle Build Target: java.lang.NullPointerException
When removing com.android.support:design:22.2.0 (and adding back v4 and AppCompat), build is successful.
Another similar issue didn't help me
Notice that i'm building using Intellij 14
I ran the app using android studio and not IntelliJ 14 and got a different error:
`Error:(1) Attribute "insetForeground" has already been defined`
So if someone is running IntelliJ 14, until next update of Intellij 14 I guess It's safer to use android studio 1.3.+ (or at least check for errors using android studio.
If one get the same error.
go to attr.xml and remove declare-styleable name="ScrimInsetsView"
using ctrl-shift-f search for insetF and remove app:insetForeground attribute from all the layout that contains such attribute.
Everything should work OK now
I had exactly the same issue. I guess it comes from an combination of mismatching parameters in grade and your xml resources..
Maybe this will help (for me it did):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'com.android.application'
...
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
}
Give the build.grade the 1.1.1, too (just in case)
// 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.1.1'
}
}
allprojects {
repositories {
jcenter()
}
}
Hopefully the next sync, clean and rebuild will pass (or fire a meaningful error message like 'color-res blabla not found').
Btw: From time to time my IntelliJ is setting itself to other Java-configs (e.g. Java8 with lambdas) - so "just in case":
Don't forget to check if your project SDK is set up correctly (File > Project-structure > project > choose the SDK).

error: package com.facebook.android does not exist in android studio project

I am new to android studio.I am developing an app which uses Facebook SDK.I have downloaded Facebbok SDK and imported it as a module to my android project.I am using latest version of android studio.So I simply imported it and did not make any change in other files for this.First I am trying to use facebook login functionality.But when I build the app I am getting following error.
error: package com.facebook.android does not exist
I could see one solution as an answer to someone's question. But i could not understand it.Please somebody help me.
check you build.gradle
it should got this dependency
if you got library project:
dependencies {
compile project(':facebook');
}
if you got jar files in libs folder:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
or just add maven central dependency to:
dependencies {
compile 'com.github.asne.facebook:facebook:3.17.2'
}
You need to add dependencies on your gradle file :-
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
above is path you need to add dependencies {} like below :-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
Is the facebook library is jar file or library project?
If is jar file, you just need to add jar file in libs folder and dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
} in build.gradle.
If is library project, you should modify your setting.gradle and build.gradle files.
Adding this line of code to the dependencies in the build.gradle file helped me get rid of the same error.
dependencies {
...
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
}
From platform=android facebook developers
-the last line of the section "Add Facebook SDK to Your Project")

Categories

Resources