Reputation: 1188
I've created a simple project in Android Studio to try it out. I'll accept that for the moment I have to had code my build.gradle file to match my IDE configuration, but as I am new to both IntelliJ and Gradle I am struggling.
The project was created with a default blank activity. I created a simple, very noddy, View class given below:
package com.example.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by steve on 02/06/13.
*/
public class GraphView extends View {
/** The system logger. */
protected transient final Logger log;
public GraphView(Context context) {
super(context);
// Instantiate the system logger.
log = LoggerFactory.getLogger(getClass());
}
public GraphView(Context context, AttributeSet attrs) {
super(context, attrs);
// Instantiate the system logger.
log = LoggerFactory.getLogger(getClass());
}
public GraphView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// Instantiate the system logger.
log = LoggerFactory.getLogger(getClass());
}
}
In order to get it to compile/parse within the IDE I added the Logback JAR libraries to the same libs directory the android-support-v4.jar file is located. A quick modify of the Project Structure and all appears to work fine. Within the IDE's editor I can see the methods on the Logger
and LoggerFactory
classes.
In order to deploy the noddy app to my Nexus 4 I modified build.gradle file to also reference the libraries:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/logback-android-1.0.10.2.jar')
compile files('libs/slt4j-api-1.7.5.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
It builds just fine, it deploys it on the phone, but when the default activity in started I get a runtime error:
Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at com.example.view.GraphView.<init>(GraphView.java:29)
... 25 more
What have I missed?
Many thanks in advance.
Steve
Upvotes: 0
Views: 6259
Reputation: 1188
Found the answer here.
After adding a library you need to run ./gradlew clean
in the project root before building.
Upvotes: 2
Reputation: 2383
UPDATE
You likely still have some kind of typo in there.
I fetched the android SDK and attempted to compile a simple Hello world project with your build file and it works. That implies that you may have a typo, missing jar file or something like that.
Make sure that the jars file are present with the correct names too!
Below is the build.gradle (compile files is used only once, but that shouldn't matter, I typically don't use the filesystem without a remote repository):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar', 'libs/logback-android-1.0.10.2.jar', 'libs/slf4j-api-1.7.5.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Could it be slf4j-api-1.7.5.jar instead of slt4j-api-1.7.5.jar?
I think that you've got a typo in your dependencies section.
Upvotes: 0