2015-10-15 113 views
4

我已經嘗試過兩次讓android-apt工作,因爲它是我想要使用的第三方庫(AndroidAnnotations和PermissionsDispatcher)所必需的,而且這兩次我都抨擊我直到我厭倦了聽到squ sound聲。無法使用android-apt工作

問題? Android Studio中根本無法找到或獲取相關性:

Error:Could not find com.neenbedankt.gradle:plugins:android-apt. 
Searched in the following locations: 
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt.pom 
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt-1.8.jar 
    https://jcenter.bintray.com/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt.pom 
    https://jcenter.bintray.com/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt-1.8.jar 
    https://repo1.maven.org/maven2/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt.pom 
    https://repo1.maven.org/maven2/com/neenbedankt/gradle/plugins/android-apt/plugins-android-apt-1.8.jar 
Required by: 
    :MaterialQuoter:unspecified 

我可能做出某種可笑的錯誤的(?我的意思是,這些庫將不會看到任何其它方式使用,正確的),但我可以」 t看看我做錯了什麼。

我正在運行Android Studio 1.4,以防萬一它有某種相關性。

這是項目的gradle這個文件:

buildscript { 
    repositories { 
     jcenter() 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.3.0' 
     classpath 'com.neenbedankt.gradle:plugins:android-apt:1.8' 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     mavenCentral() 
     mavenLocal() 
    } 
} 

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 

dependencies { 
    compile 'com.github.hotchemi:permissionsdispatcher:1.2.1' 
    apt 'com.github.hotchemi:permissionsdispatcher-processor:1.2.1' 
} 

這是我主要工作的模塊文件的gradle:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 

    defaultConfig { 
     applicationId "com.callisto.materialquoter" 
     multiDexEnabled true 
     minSdkVersion 21 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    packagingOptions { 
     exclude 'META-INF/license.txt' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/notice.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/ASL2.0' 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1' 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:recyclerview-v7:23.0.1' 
    compile 'com.android.support:cardview-v7:23.0.1' 
    compile 'com.android.support:design:23.0.1' 
    compile 'com.google.code.findbugs:jsr305:1.3.9' 
    compile 'com.google.android.gms:play-services:8.1.0' 
    compile 'com.github.hotchemi:permissionsdispatcher:1.2.1' 
    compile 'org.roboguice:roboguice:3.+' 
    provided 'org.roboguice:roboblender:3.+' 
    compile 'org.codepond:wizardroid:1.3.0' 
    compile ('com.octo.android.robospice:robospice:1.4.14') { 
     exclude group: 'org.apache.commons', module: 'commons-io' 
    } 
    compile ('com.octo.android.robospice:robospice-cache:1.4.14') { 
     exclude group: 'org.apache.commons', module: 'commons-io' 
    } 
    compile ('com.octo.android.robospice:robospice-spring-android:1.4.14') { 
     exclude group: 'org.apache.commons', module: 'commons-io' 
    } 
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13' 
    compile 'de.greenrobot:greendao:2.0.0' 
} 
+1

請添加一些顯示錯誤 –

+0

看起來一見鍾情。你有沒有複製依賴,'apt'和'apply'行?嘗試手動輸入這些內容,因爲它發生了複製粘貼引入了不可見的空間,從而破壞了配置。 – botteaap

+0

我只是嘗試評論一切,然後再次手動輸入。沒有什麼改變......我先添加了'classpath'行,嘗試同步,再次得到錯誤,然後添加剩下的部分,並再次嘗試同步 - 最後出現另一個錯誤。 有沒有辦法手動將這些依賴項導入到'm2repository'中?說,我手動下載所有東西並將其粘貼到Gradle的某個地方找到它? –

回答

5

我有同樣的問題。這幫助我弄清楚了。

在應用程序模塊本身,添加這些行(順序很重要):

buildscript { 
    repositories { 
     mavenCentral() 
    } 

    dependencies { 
     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 
    } 
} 

apply plugin: 'com.android.application' 
apply plugin: 'android-apt' 


dependencies { 
    compile 'com.github.hotchemi:permissionsdispatcher:[email protected]' 
    apt 'com.github.hotchemi:permissionsdispatcher-processor:1.2.1' 
} 
+0

事實證明,我將這些行放在整個項目的Gradle文件上。在這個和android-apt-example項目之間尋找幫助可以解決問題。非常感謝......你剛剛找到了一個讓我折磨了好幾個月頭痛的問題。現在我可以測試AndroidAnnotations是否比RoboGuice更好。 :P –

+0

在'repositories'中,我有'maven {url'https://maven.fabric.io/public'}''。當我在該行後面添加'mavenCentral()'時,它工作正常。 –

2

由於Android的搖籃插件2.2版本,以前由Android的易提供的所有功能現在可在Android插件中。這意味着Android的易正式過時;)

因此,

  1. 確保您更新搖籃插件爲> = 2.2
  2. 代替apt使用annotationProcessor

Ref:https://bitbucket.org/hvisser/android-apt/wiki/Migration

+0

我不認爲這真的回答了這個問題。 OP使用的第三方庫需要android-apt,因此刪除它可能不是一個選項。 –

0

我想通過這種方式在Android St音頻2.2.1:

這讓我可以在主項目上同時在庫上使用Butterknife。

請注意,在圖書館使用Butterknife註釋時,請使用R2 .id.blah而不是R.id.blah。

希望適用於所有人。

同時檢查this link

1)項目文件的gradle:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.1' 
     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 
} 

2)的應用程序文件graddle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 

    defaultConfig { 
     minSdkVersion 21 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

    ... 


} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    testCompile 'junit:junit:4.12' 

    ... 

    //Butterknife https://github.com/JakeWharton/butterknife#library-projects 
    compile 'com.jakewharton:butterknife:8.4.0' 
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' 

    ... 
} 

3)庫graddle文件

apply plugin: 'com.android.library' 
apply plugin: 'com.jakewharton.butterknife' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "25.0.0" 

    defaultConfig { 
     minSdkVersion 21 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 

    //Butterknife 
    compile 'com.jakewharton:butterknife-annotations:8.4.0' 
    compile 'com.jakewharton:butterknife:8.4.0' 
    ... 
}