将 butterknife 添加到 android 库项目会导致库 类 出现编译时错误 "package does not exists"
Adding butterknife to android library project gives compile time error "package does not exists" for library classes
我试图将 butterknife 库添加到我的库项目中并按照步骤操作。
https://github.com/JakeWharton/butterknife.
项目在 gradle 同步时没有显示任何错误,但是当我尝试 运行 应用程序时,它 returns 编译错误包没有为我的库退出 类 我已经在应用程序中使用了。
error
error:package com.sample.library.BaseMainActivity does not exist
error:cannot find symbol class BaseMainActivity
error:cannot find symbol variable super
project/build.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.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.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
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.sample.test"
minSdkVersion 9
targetSdkVersion 23
versionCode 3
versionName "v3.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// ButterKnife
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
testCompile 'junit:junit:4.12'
}
library/build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 9
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.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
//Dagger
apt 'com.google.dagger:dagger-compiler:2.2'
compile 'com.google.dagger:dagger:2.2'
provided 'javax.annotation:jsr250-api:1.0'
// ButterKnife
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
如果删除 ButterKnife 依赖项,应用程序 运行 不会出错。图书馆项目以某种方式与 butterknife 图书馆发生冲突,但无法找出原因和方式。请帮助我在这方面做错了什么。
我在我的应用程序中测试了您的库,它构建正常
这里是 gradle
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
repositories {
maven { url "https://jitpack.io" }
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.jakewharton:butterknife:8.0.1'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'net.grandcentrix.tray:tray:0.9.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'
//Dagger
apt 'com.google.dagger:dagger-compiler:2.2'
compile 'com.google.dagger:dagger:2.2'
provided 'javax.annotation:jsr250-api:1.0'
}
如果升级 library
中的 Dagger
版本,一切编译都没有问题。
使用:
apt 'com.google.dagger:dagger-compiler:2.4'
compile 'com.google.dagger:dagger:2.4'
我试图将 butterknife 库添加到我的库项目中并按照步骤操作。
https://github.com/JakeWharton/butterknife.
项目在 gradle 同步时没有显示任何错误,但是当我尝试 运行 应用程序时,它 returns 编译错误包没有为我的库退出 类 我已经在应用程序中使用了。
error
error:package com.sample.library.BaseMainActivity does not exist
error:cannot find symbol class BaseMainActivity
error:cannot find symbol variable super
project/build.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.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.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
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.sample.test"
minSdkVersion 9
targetSdkVersion 23
versionCode 3
versionName "v3.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// ButterKnife
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
testCompile 'junit:junit:4.12'
}
library/build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 9
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.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
//Dagger
apt 'com.google.dagger:dagger-compiler:2.2'
compile 'com.google.dagger:dagger:2.2'
provided 'javax.annotation:jsr250-api:1.0'
// ButterKnife
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
如果删除 ButterKnife 依赖项,应用程序 运行 不会出错。图书馆项目以某种方式与 butterknife 图书馆发生冲突,但无法找出原因和方式。请帮助我在这方面做错了什么。
我在我的应用程序中测试了您的库,它构建正常
这里是 gradle
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
repositories {
maven { url "https://jitpack.io" }
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.jakewharton:butterknife:8.0.1'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'net.grandcentrix.tray:tray:0.9.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'
//Dagger
apt 'com.google.dagger:dagger-compiler:2.2'
compile 'com.google.dagger:dagger:2.2'
provided 'javax.annotation:jsr250-api:1.0'
}
如果升级 library
中的 Dagger
版本,一切编译都没有问题。
使用:
apt 'com.google.dagger:dagger-compiler:2.4'
compile 'com.google.dagger:dagger:2.4'