Android Studio で簡単なプロジェクトを作成して試してみました。今のところ、IDE 構成に合わせて build.gradle ファイルをコーディングする必要があることを受け入れますが、IntelliJ と Gradle の両方を初めて使用するので苦労しています。
プロジェクトは、デフォルトの空白のアクティビティで作成されました。以下に示す、シンプルで非常にうなずく View クラスを作成しました。
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());
}
}
IDE 内でコンパイル/解析するために、Logback JAR ライブラリを android-support-v4.jar ファイルがある同じ libs ディレクトリに追加しました。プロジェクト構造をすばやく変更すると、すべてが正常に機能するように見えます。IDE のエディター内で、Logger
およびLoggerFactory
クラスのメソッドを確認できます。
noddy アプリを Nexus 4 にデプロイするために、build.gradle ファイルを変更してライブラリも参照するようにしました。
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
}
}
それは問題なくビルドされ、電話にデプロイされますが、デフォルトのアクティビティが開始されると、ランタイム エラーが発生します。
Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at com.example.view.GraphView.<init>(GraphView.java:29)
... 25 more
私は何を逃したのですか?
よろしくお願いします。
スティーブ