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