Unable to import mockito in android studio - android

I've started writing the unit tests for my application. I'm using Mockito to mock the objects.
This is the link I followed to include the mockito dependency in my app level gradle file.
The problem is I'm unable to import mockito into my test class.
Here's my app build.gradle file for the reference.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
lintOptions {
disable 'HardcodedText','TextFields','OnClick'
}
}
repositories {
jcenter()
mavenCentral()
maven() {
name 'SonaType snapshot repository'
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
ext {
robobindingVersion = 'latest.integration'
//robobindingVersion = '0.8.6-SNAPSHOT'
}
dependencies {
testCompile "org.mockito:mockito-core:1.+"
compile("org.robobinding:robobinding:$robobindingVersion:with-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile('org.robolectric:robolectric:3.0-rc2') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
apt "org.robobinding:codegen:$robobindingVersion"
compile 'junit:junit:4.12'
}

Try changing
compile "org.mockito:mockito-core:1.+" or implementation "org.mockito:mockito-core:1.+"
to
androidTestImplementation "org.mockito:mockito-core:1.+"

I had the same problem and solve it just by using:
compile "org.mockito:mockito-core:1.+"
Hope it helps =]

Check this link .... this may useful
https://stackoverflow.com/a/34148132/5185201
// add dexOptions
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
// Enabling multidex support.
multiDexEnabled true

Manually importing the mockito jar file did the thing for me.
To do that, first create a directory called "libs" in your app directory. Take note that this directory should be in the same level as that of the src/main and build directories.
Next, download the mockito jar file and paste it into the libs directory.
Include that into your dependencies in the app level build.gradle file:
dependencies {
compile files('libs/add-your-jar-file-name-here')
}
Sync the gradle and that should do the job.
Refer to this answer for more detailed answer with snapshots.

Related

Android Studio unable to run project

I'm trying to run old project that runs for a lot of time.
Suddenly I'm unable to run it.
This is the build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.1.3"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
// For MobFox
maven {
url "https://jitpack.io"
}
// For AppBrain SDK
maven {
url 'http://swisscodemonkeys.github.io/appbrain-sdk/maven'
}
}
}
This is the gradle-wrapper.properties file:
#Sun Nov 12 11:49:59 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
org.gradle.jvmargs=-Xmx4608M
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
And i get this error:
Gradle sync failed: Could not find gradle.jar (com.android.tools.build:gradle:3.0.0).
Searched in the following locations:https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar
When I change the order between the google() and jcenter(), this error disappears but i get this error now:
error: cannot access zzbfm
class file for com.google.android.gms.internal.zzbfm not found
Any idea of how I can fix this issue? I prefer to not upgrade the Gradle version since this is a complicated project and I need to upload an update really soon without making a lot of changes.
EDIT
This is the app build.gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
}
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
multiDexEnabled true
minSdkVersion 16
targetSdkVersion 26
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
buildTypes {
debug {
debuggable true
buildConfigField "boolean", "CRASH_LOGGING", "true"
applicationIdSuffix ".dev"
}
release {
debuggable false
buildConfigField "boolean", "CRASH_LOGGING", "true"
minifyEnabled true
proguardFiles 'proguard-project.txt'
}
}
flavorDimensions "regular"
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
implementation "com.android.support:support-compat:26.1.0"
compile 'com.google.android.gms:play-services-auth:11.8.0'
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
compile 'org.apache.commons:commons-lang3:3.6'
compile 'joda-time:joda-time:2.9.9'
compile('org.simpleframework:simple-xml:2.7.1') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
// UI & VIEWS
compile 'com.tuyenmonkey:mkloader:1.4.0'
compile 'com.mikhaellopez:circularimageview:3.0.2'
compile 'com.github.mmin18:realtimeblurview:1.1.0'
compile 'com.github.PhilJay:ValueBar:v1.0.2'
// IMAGE HANDLING
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
// NETWORK HANDLING
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.9.0'
//RETORFIT
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile('com.squareup.retrofit2:converter-simplexml:2.3.0') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
compile 'com.squareup.retrofit2:converter-scalars:2.3.0'
// FABRIC
compile('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true;
}
// ADS
compile 'com.flurry.android:analytics:8.2.0#aar'
compile 'com.appbrain:appbrain-sdk:14.60#aar'
compile(name: 'android-ad-sdk', ext: 'aar')
compile(name: 'SOMAAndroid-9.1.5-release', ext: 'aar')
compile 'com.applovin:applovin-sdk:+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
samsungDebugCompile files('libs/sdk-v1.0.0.jar')
samsungDebugCompile files('libs/motion-v2.2.2.jar')
samsungReleaseCompile files('libs/sdk-v1.0.0.jar')
samsungReleaseCompile files('libs/motion-v2.2.2.jar')
//debug DB
debugCompile 'com.amitshekhar.android:debug-db:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
Just go the file menu and click on invalidate cache and restart the android studio.
Then from build menu do clean, rebuild and make project.

Gradle duplicate entry error: META-INF/MANIFEST.MF (Or how to delete a file from jar)

I've cloned a github repository because I wanted to study the code, but when I tried to build it in Android Studio, I ran into some trouble.
After adding the google maven repository (as prompted by Android Studio) and updating both the Gradle Plugin Version and the Grade Version (to 3.5.2 and to 5.4.1, respectively), the build fails because of the following error:
Cause: duplicate entry: META-INF/MANIFEST.MF
And this, to be more specific:
Caused by: java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF
Here is my project level build.gradle file:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
Here's my module build.gradle file (before trying anything):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.thelittlenaruto.supportdesignexample"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:22.2.1')
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1#aar'
}
Here's what I've tried so far:
Adding the following to the android section of my module build.gradle file:
sourceSets {
main{
java{
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
}
}
Adding this:
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST'
sourceSets.main.res.filter.exclude 'META-INF/MANIFEST.MF'
Also this:
packagingOptions {
apply plugin: 'project-report'
exclude '**/META-INF/MANIFEST'
exclude '**/META-INF/MANIFEST.MF'
exclude 'META-INF/MANIFEST'
exclude 'META-INF/MANIFEST.MF'
exclude '!META-INF/MANIFEST.MF'
}
And this:
packagingOptions {
pickFirst '**/META-INF/MANIFEST'
pickFirst '**/META-INF/MANIFEST.MF'
pickFirst 'META-INF/MANIFEST'
pickFirst 'META-INF/MANIFEST.MF'
pickFirst '!META-INF/MANIFEST.MF'
}
This:
aaptOptions {
ignoreAssetsPattern "!META-INF/MANIFEST.MF"
ignoreAssetsPattern "META-INF/MANIFEST.MF"
}
I think I've tried mostly everything in this question:
How to exclude certain files from Android Studio gradle builds?
Nothing worked.
After searching for a solution, I think the problem is that I have duplicated dependencies. So I've tried the following:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:22.2.1'){
exclude module: 'support-v4'
}
implementation ('com.android.support:design:22.2.1')
implementation 'com.github.frankiesardo:linearlistview:1.0.1#aar'
}
And this:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:design:22.2.1'){
exclude module: 'support-v7'
}
implementation 'com.github.frankiesardo:linearlistview:1.0.1#aar'
}
I still get the same error.
What am I doing wrong?
As Rajen Raiyarela said, go to File->Project Structure->Project->Android Gradle Plugin Version and downgrade it from 3.5.2 to 3.5.1.
Set project dependencies to:
classpath 'com.android.tools.build:gradle:3.5.3'
or latest one.
Note: by doing this, my problem has been resolved.
This issue is happening because of duplicate dependencies.
Check for multiple dependencies in the Gradle app.
Either package it once or not at all:
android {
packagingOptions {
pickFirst "META-INF/MANIFEST.MF"
// exclude "META-INF/MANIFEST.MF"
}
}
as #rubo77 says and after my confirmation:
Latest solution
Upgrade gradle version
eg:
from 3.5.2 to 3.5.3
from 3.5.2 to 3.5.4
Obsolete solution:
downgrade from 3.5.2 to 3.5.1
my choice is : upgrade from 3.5.2 to 3.5.4
build.gradle:
dependencies {
// classpath 'com.android.tools.build:gradle:3.5.2'
// classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.5.4'
}

Build Failed: Program Type Already Present

I have searched online about this error and the issue always seems to end up being some sort of dependency conflict. I think I am supposed to add exclude after certain dependencies, but I am unsure which one(s). It's also unclear based on the error which dependency I should actually exclude; all I know is that the group is probably com.android.support...
Here's what I've tried:
Adding multiDexEnabled true to my defaultConfig block in build.gradle.
Cleaning the project in Android Studio.
Manually deleting (from the file system) the entire .gradle directory.
I've made sure compileSdkVersion and targetSdkVersion are the same.
I've made sure all my Android dependencies use the same version (namely 26.1.0).
Despite all this, I still get this error when I build:
Program type already present: android.support.compat.R$bool
and from the Java compiler:
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
F:\ExampleProject\app\build\intermediates\transforms\dexBuilder\debug\115,
F:\ExampleProject\app\build\intermediates\transforms\externalLibsDexMerger\debug\0
Here is my module's build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.myapp.exampleproject"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.1.0'
}
and lastly, my project's build.gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any help in rectifying this would be greatly appreciated.
This is a problem with Glide 4.1.0. Use the version 4.1.1 instead which fix the bug by remove the R*.class file from their dependencies. (source)
This is probably because of Glide library. Try to exclude the support library from it with:
// add support-fragment removed from Glide.
implementation "com.android.support:support-fragment:26.1.0"
implementation ('com.github.bumptech.glide:glide:4.1.0') {
exclude group: 'com.android.support'
exclude module: 'support-fragment'
exclude module: 'appcompat-v7'
}
You can see the support library inside Glide at Glide build.gradle
Solution:
implementation ('com.github.bumptech.glide:glide:4.1.0') {
exclude group: 'com.android.support'
exclude module: 'support-fragment'
exclude module: 'appcompat-v7'
}

ClassNotFoundException when referencing Kotlin classes

I try to start migrating a Java based multidexed project to Kotlin but I get ClassNotFoundException whenever the app tries to reference a Kotlin class. The weird thing is that the same code sometimes works sometimes it doesn't. There are computers which produce working apk and others don't. Sometimes a rebuild is enough to solve the problem.
I've tried to google it but I've only found this thread, but there is no resolution. Does this thing work properly for everyone else or aren't there any multidexed Kotlin project yet?
I've tried with AS 2.3.3 and AS 3.0.0-beta6, 2.3.3 android plugun, kotoin version 1.1.50, without proguard.
buildscript {
ext.kotlin_version = '1.1.50'
ext.android_plugin_version = '2.3.3'
ext.support_lib_version = '25.3.1'
ext.play_services_version = '11.0.4'
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.google.firebase:firebase-plugins:1.1.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
apply plugin: "com.android.application"
apply plugin: "me.tatarka.retrolambda"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "com.google.firebase.firebase-perf"
repositories {
mavenCentral()
jcenter()
maven {
url "https://jitpack.io"
}
}
android {
signingConfigs {
debug {
...
}
}
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.my.app"
signingConfig signingConfigs.debug
minSdkVersion 14
targetSdkVersion 25
versionCode 13
versionName "2.0.1.b8face5"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
testInstrumentationRunner "com.my.app.TestRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//this is because instabug uses rxjava 1 and now we have both 1 and 2 on the classpath
packagingOptions {
exclude "META-INF/rxjava.properties"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
}
}
}
dependencies {
compile fileTree(include: "*.jar", dir: "libs")
// Force usage of support annotations in the test app, since it is internally used by the runner module.
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.1") {
exclude module: "support-annotations"
}
androidTestCompile("com.android.support.test.espresso:espresso-contrib:2.2.1") {
// Necessary to avoid version conflicts
exclude group: "com.android.support", module: "appcompat"
exclude group: "com.android.support", module: "support-v4"
exclude group: "com.android.support", module: "support-annotations"
exclude module: "recyclerview-v7"
}
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:appcompat-v7:$support_lib_version"
compile "com.android.support:recyclerview-v7:$support_lib_version"
compile "com.android.support:design:$support_lib_version"
compile "com.android.support:cardview-v7:$support_lib_version"
compile "com.google.android.gms:play-services-auth:$play_services_version"
compile "com.google.android.gms:play-services-identity:$play_services_version"
compile "com.google.android.gms:play-services-location:$play_services_version"
compile "com.google.android.gms:play-services-maps:$play_services_version"
compile "com.google.firebase:firebase-core:$play_services_version"
compile "com.google.firebase:firebase-crash:$play_services_version"
compile "com.google.firebase:firebase-perf:$play_services_version"
compile "com.google.code.gson:gson:2.8.1"
compile "com.google.maps.android:android-maps-utils:0.4"
compile "com.squareup.retrofit2:retrofit:2.3.0"
compile "com.squareup.retrofit2:converter-gson:2.3.0"
compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
compile "io.reactivex.rxjava2:rxandroid:2.0.1"
compile "io.reactivex.rxjava2:rxjava:2.1.3"
compile "com.squareup.okhttp3:okhttp-urlconnection:3.8.1"
compile "com.facebook.stetho:stetho:1.5.0"
compile "com.facebook.stetho:stetho-okhttp3:1.5.0"
compile "com.squareup.picasso:picasso:2.5.2"
compile "com.jakewharton:butterknife:8.2.1"
compile "com.annimon:stream:1.1.8"
compile "com.github.lawloretienne:quickreturn:0.0.1"
compile "com.github.chrisbanes:PhotoView:1.2.6"
compile "fr.baloomba:viewpagerindicator:2.4.2"
compile "com.github.bluejamesbond:textjustify-android:2.1.6"
compile "com.turingtechnologies.materialscrollbar:lib:10.1.4"
compile "com.github.PhilJay:MPAndroidChart:v3.0.1"
compile "com.android.support:multidex:1.0.1"
compile "com.bugsnag:bugsnag-android:3.9.0"
//TODO check periodically whether they upgraded to rxjava 2
compile "com.instabug.library:instabug:4.2.11"
testCompile "junit:junit:4.12"
androidTestCompile "com.android.support:support-annotations:$support_lib_version"
androidTestCompile "com.android.support.test:runner:0.5"
androidTestCompile "com.android.support.test:rules:0.5"
annotationProcessor "com.jakewharton:butterknife-compiler:8.2.1"
compile "com.google.dagger:dagger:2.5"
annotationProcessor "com.google.dagger:dagger-compiler:2.5"
provided "javax.annotation:jsr250-api:1.0"
}
apply plugin: "com.google.gms.google-services"
Finally I was able to solve the issue! The exception was caused by a RetroLambda bug and thankfully disappeared after I updated to 3.7.0. The build was nondeterministic because it seems gradle clean doesn't delete everything. After I manually deleted the build folder both in the app and root module, the results became deterministic.
If you are using Java 8 then you should also use Kotlin jre8.
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"

Cannot get android-apt working

Twice already I've tried to get android-apt to work, because it's required by the 3rd-party libraries I wanted to use (AndroidAnnotations and PermissionsDispatcher), and both times I bashed my head against the wall until I got tired of hearing the squishing sound.
The problem? Android Studio simply fails to find or fetch the dependencies:
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
I'm probably making some sort of ridiculous mistake (I mean, those libraries would not see any use otherwise, right?), but I can't see what I'm doing wrong.
I'm running Android Studio 1.4, in case it's somehow relevant.
This is the gradle file for the project:
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'
}
This is the gradle file for the module I'm mostly working on:
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'
}
I had the same problem. This helped me to figure it out.
On the app module itself, add these lines (order is important):
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:1.2.1#aar'
apt 'com.github.hotchemi:permissionsdispatcher-processor:1.2.1'
}
As of the Android Gradle plugin version 2.2, all functionality that was previously provided by android-apt is now available in the Android plugin. This means that android-apt is officially obsolete ;)
Thus,
Make sure you've updated your Gradle plugin to be >= 2.2
Instead of apt use annotationProcessor
Ref: https://bitbucket.org/hvisser/android-apt/wiki/Migration
I figured this way on Android Studio 2.2.1:
This lets me use Butterknife on the main project and also on the library at the same time.
Please note that, on the library, use R2.id.blah instead of R.id.blah when using Butterknife annotations.
Hope works for all.
Also check this link
1) project gradle file:
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) app graddle file
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) library graddle file
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'
...
}

Categories

Resources