Im trying to use Kotlin with Android Studio 3.0 with my existing project.
I have created a fragment using kotlin. Im trying to use the kotlin fragment in my Java Activity. But everytime i try to run it I get
Error:(209, 5) error: cannot find symbol class BlankFragment
BlankFragment.kt
import android.content.Context
import android.net.Uri
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class BlankFragment : Fragment() {
// TODO: Rename and change types of parameters
private var mParam1: String? = null
private var mParam2: String? = null
private var mListener: OnFragmentInteractionListener? = null
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1)
mParam2 = getArguments().getString(ARG_PARAM2)
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?): View
= FragmentUi<Fragment>().createView(AnkoContext.create(ctx, this))
}
class FragmentUi<T>: AnkoComponent<T> {
override fun createView(ui: AnkoContext<T>) = with(ui) {
verticalLayout {
textView {
text = R.string.app_name
}
}
}
}
project - build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.1'
ext.anko_version = '0.10.1'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha5'
classpath 'com.google.gms:google-services:3.0.0'
classpath "io.realm:realm-gradle-plugin:3.0.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: 'realm-android'
android {
signingConfigs {
splits {
abi {
enable true //enables the ABIs split mechanism
reset() //reset the list of ABIs to be included to an empty string
include 'x86', 'armeabi', 'armeabi-v7a', 'mips', 'x86_64', 'arm64-v8a'
universalApk true
}
}
project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(
com.android.build.OutputFile.ABI), 0) * 10000000 + android.defaultConfig.versionCode
}
}
}
compileSdkVersion 25
buildToolsVersion '26'
defaultConfig {
applicationId "com.example"
minSdkVersion 15
targetSdkVersion 23
versionCode 20
versionName "v.32"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseConfig
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
repositories {
maven { url "https://jitpack.io" }
}
lintOptions {
disable "ResourceType"
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:10.2.6'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.google.code.gson:gson:2.6.2'
// compile 'io.realm:realm-android:0.87.5'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.github.jkwiecien:EasyImage:1.3.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.yarolegovich:lovely-dialog:1.0.4'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.github.ParkSangGwon:TedPermission:v1.0.12'
compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
compile 'com.github.piotrek1543:CustomSpinner:0.1'
compile 'com.github.ganfra:material-spinner:1.1.1'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.appyvet:materialrangebar:1.3'
compile 'com.afollestad.material-dialogs:core:0.9.4.5'
compile 'com.mixpanel.android:mixpanel-android:4.+'
compile 'com.github.ericwlange:AndroidJSCore:3.0.1'
compile 'com.android.support:multidex:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
compile "org.jetbrains.anko:anko-sdk25:$anko_version"
compile "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
compile files('libs/bcpkix-jdk15on-1.56.0.0.jar')
compile files('libs/core-1.56.0.0.jar')
compile files('libs/prov-1.56.0.0.jar')
}
apply plugin: 'com.google.gms.google-services'
You seem to be missing all Kotlin dependencies other than having the version declared (you should probably update that to 1.1.3 as well, which is the latest available as of now).
You can configure your project in two ways:
Remove the Kotlin version you have declared, and then go to Tools -> Kotlin -> Configure Kotlin in Project, and follow the steps presented there.
Alternatively, you can do it in a more manual way by following the steps described here to set up the Kotlin Gradle plugin, including following the link that's there and setting up the standard library dependency as well.
Finally was able to get it working. For anyone who is going through a similar problem.
project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.3'
ext.anko_version = '0.10.1'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.0.0-alpha5'
classpath 'com.google.gms:google-services:3.0.0'
classpath "io.realm:realm-gradle-plugin:3.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app build.gradle
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
signingConfigs {
splits {
abi {
enable true //enables the ABIs split mechanism
reset() //reset the list of ABIs to be included to an empty string
include 'x86', 'armeabi', 'armeabi-v7a', 'mips', 'x86_64', 'arm64-v8a'
universalApk true
}
}
project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(
com.android.build.OutputFile.ABI), 0) * 10000000 + android.defaultConfig.versionCode
}
}
}
compileSdkVersion 25
buildToolsVersion '26'
defaultConfig {
applicationId "com.example"
minSdkVersion 15
targetSdkVersion 23
versionCode 20
versionName "v.32"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseConfig
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
repositories {
maven { url "https://jitpack.io" }
}
lintOptions {
disable "ResourceType"
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:10.2.6'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.google.code.gson:gson:2.6.2'
// compile 'io.realm:realm-android:0.87.5'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.github.jkwiecien:EasyImage:1.3.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.yarolegovich:lovely-dialog:1.0.4'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.github.ParkSangGwon:TedPermission:v1.0.12'
compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
compile 'com.github.piotrek1543:CustomSpinner:0.1'
compile 'com.github.ganfra:material-spinner:1.1.1'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.appyvet:materialrangebar:1.3'
compile 'com.afollestad.material-dialogs:core:0.9.4.5'
compile 'com.mixpanel.android:mixpanel-android:4.+'
compile 'com.github.ericwlange:AndroidJSCore:3.0.1'
compile 'com.android.support:multidex:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
compile "org.jetbrains.anko:anko-sdk25:$anko_version"
compile "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile files('libs/bcpkix-jdk15on-1.56.0.0.jar')
compile files('libs/core-1.56.0.0.jar')
compile files('libs/prov-1.56.0.0.jar')
}
apply plugin: 'com.google.gms.google-services'
Related
I have searched a lot of posts about this issue and all of them apparently got resolved after upgrading to 'com.google.gms:google-services:4.0.2'from 3.3. However i am still getting the same error.
I need to use data binding for the project . Disabling it compiles the project, but i can't find a way around data binding
Any help would be appreciated
My project build.gradle
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.2'
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url "https://maven.google.com"
}
flatDir {
dirs 'libs'
}
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My app build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
signingConfigs {
WalletAppSignConfig {
keyAlias '********'
keyPassword '********'
storeFile file('********')
storePassword '********'
}
}
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "********"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField "String", "RNS_MESSAGE_TAG", "\"payload\""
// Sample GCM ID
buildConfigField "String", "GCM_ID", "\"********\""
// Default location of the CMS-D
buildConfigField "String", "CMS_URL", "\"http://********/cms\""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.WalletAppSignConfig
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
android{
dataBinding{
enabled=true;
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('********') {
transitive = true
}
compile '********'
compile('net.sf.flexjson:flexjson:3.2') {
transitive = true
}
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
compile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
//compile "android.arch.persistence.room:runtime:1.0.0-alpha4"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
//annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha4"
// compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.google.firebase:firebase-core:16.0.0'
compile 'com.google.firebase:firebase-messaging:17.0.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
//compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
testCompile 'junit:junit:4.12'
}
android.applicationVariants.all { variant ->
task("_generate${variant.name}Javadoc", type: Javadoc) {
********
********
******** }
}
//apply plugin: 'realm-android'
i imported a project into a workspace in Android studio, and the file structure of the project does not seem in a proper condition as shown in image-1.
Also, when I tried to build and compile the project I received the following error:
Error:(20, 0) Could not find method compile() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File
also in the project,the build.gradle(project) exists twice and build.gradle(app) exists once as shown in image-2
please have a look at the below gradle files, and please let me know how to correct this error and why I am getting it.
build.gradle(app):
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2' // '4.2.0'
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'eu.man.m24wsapp'
}
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "eu.man.m24wsapp"
targetSdkVersion 25
minSdkVersion 10
versionCode 1
versionName "1.1.18"
}
signingConfigs {
release {
storeFile file("../wsapp.keystore")
storePassword "7s5zhgknsIXxHgw"
keyAlias "man_mobile24"
keyPassword "manmobile242014"
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
release {
minifyEnabled false // 15.05.2017 avk, enables/disables proguard
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
def name = output.outputFile.name.replace("app", "Man");
name = name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk");
output.outputFile = new File(output.outputFile.parent, name)
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':appcompat')
compile project(':securepreferences')
compile 'com.android.support:support-v4:25.2.0' // .0.1
compile 'com.google.android.gms:play-services:4.3.23'
// compile 'com.google.android.gms:play-services-maps:10.0.1'
// compile 'com.google.android.gms:play-services-location:10.0.1'
// AVK 05.02.2017 compile 'com.github.chrisbanes.photoview:library:1.2.2'
compile 'com.github.chrisbanes.photoview:library:1.2.4'
compile 'com.google.code.gson:gson:2.7' // 2.4
// AVK 5.2.2017 compile 'com.squareup:otto:1.3.6'
compile 'com.squareup:otto:1.3.8'
// AVK 5.2.2017 compile 'com.squareup.okhttp:okhttp:1.5.4'
// AVK 5.2.2017 compile 'com.squareup.okhttp:okhttp:2.5.0'
// AVK 5.2.2017 compile 'com.squareup.okhttp:okhttp:2.6.0' // oder
compile 'com.squareup.okhttp:okhttp:2.2.0' // 7.5' // oder
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' // 7.5' // oder
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
// AVK 5.2.2017 compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.6.0'
compile 'com.squareup.picasso:picasso:2.4.0'
//compile 'com.squareup.picasso:picasso:2.2.0'
// AVK 5.3.2017 compile 'com.squareup.picasso:picasso:2.4.0'
// AVK 3.2.2017 compile 'com.squareup.retrofit:retrofit:1.5.1'
// AVK 3.2.2017 compile group: 'com.squareup.retrofit', name: 'retrofit', version: '1.9.0'
compile 'com.squareup.retrofit:retrofit:1.8.0'
// AVK 5.2.2017 compile 'com.squareup.retrofit2:retrofit:2.1.0'
}
**build.gradle(project)**:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' // 1.8?
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('app/libs/android-viewbadger.jar')
compile files('app/libs/iDappsImagesLib_v0.2.jar')
compile files('app/libs/iDappsToolsLib_v0.1.jar')
compile files('gradle/wrapper/gradle-wrapper.jar')
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
image-1:
image-2:
image-3 project properties:
image-4 gradle path:
Move quoted block from build.gradle(project) to build.gradle(app) as the compile and android comes from the application plugin
build.gradle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' // 1.8?
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
build.gradle(app)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('app/libs/android-viewbadger.jar')
compile files('app/libs/iDappsImagesLib_v0.2.jar')
compile files('app/libs/iDappsToolsLib_v0.1.jar')
compile files('gradle/wrapper/gradle-wrapper.jar')
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
I recently had a lot of problems trying to debug in my application when using Retrolambda, because of that I wanted to include Jack on my Gradle for debugging purposes.
jackOptions {
enabled true
}
Because of that, I have been going through this error and I still without finding a way to solve it.
Jackson : NoSuchMethodError for com.google.common.base.Preconditions.checkState
I have check different posts looking for a solution:
Android Studio: Gradle - build fails -- Execution failed for task ':dexDebug'
Lambda expressions crash with IncompatibleClassChangeError in Android when using jack
A larger heap for the Gradle daemon is recommended for running jack
But none of the solutions have fixed my problems. Right now my Gradle looks like:
buildscript {
ext {
use_jack = true
dagger_version = "2.8"
firebase_version = "9.6.1"
rx_version = "2.0.3"
rx_firebase_version = "1.0.0"
rx_android_version = "2.0.1"
gson_version = "2.8.0"
butterkinfe_version = "8.4.0"
support_version = "25.0.0"
target_sdk_version = 24
}
}
apply plugin: 'com.android.application'
if (!use_jack) { //Backport to apt / RetroLambda
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.myaplicattion"
minSdkVersion 15
targetSdkVersion project.properties.target_sdk_version
versionCode 1
versionName "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled use_jack
}
}
buildTypes {
debug {
minifyEnabled false
testCoverageEnabled = true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//Support
compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:design:$support_version"
//Util
compile 'com.intellij:annotations:12.0'
compile 'com.jakewharton.timber:timber:4.3.1'
compile "com.jakewharton:butterknife:$butterkinfe_version"
if (use_jack) annotationProcessor "com.jakewharton:butterknife-compiler:$butterkinfe_version"
else apt "com.jakewharton:butterknife-compiler:$butterkinfe_version"
compile 'com.github.mukeshsolanki:country-picker-android:1.1.6'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
//Glide
compile 'com.github.bumptech.glide:glide:3.7.0'
//Firebase
// compile "com.firebaseui:firebase-ui-database:0.4.0"
compile "com.google.firebase:firebase-storage:$firebase_version"
compile "com.google.firebase:firebase-messaging:$firebase_version"
compile "com.google.firebase:firebase-common:$firebase_version"
compile "com.google.firebase:firebase-auth:$firebase_version"
compile "com.google.firebase:firebase-core:$firebase_version"
compile "com.google.firebase:firebase-database:$firebase_version"
compile "com.google.firebase:firebase-crash:$firebase_version"
compile "com.github.frangsierra:rx2firebase:$rx_firebase_version"
//GSON
compile "com.google.code.gson:gson:$gson_version"
//Facebook
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
//Dagger
compile "com.google.dagger:dagger:$dagger_version"
if (use_jack) annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
else apt "com.google.dagger:dagger-compiler:$dagger_version"
//Rx
compile "io.reactivex.rxjava2:rxjava:$rx_version"
compile "io.reactivex.rxjava2:rxandroid:$rx_android_version"
//Test
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'
compile 'com.android.support.test:runner:0.5'
}
apply plugin: 'com.google.gms.google-services'
And my appgradle :
// 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.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
mavenLocal()
maven { url "https://jitpack.io" }
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I followed the instruction here to add an instrumentation test, but unfortunately Android Studio complains about the classes from the test runner package (com.android.support.test:runner:0.5) or test rules or espresso-core (cannot find symbol). If I change the dependency type from androidTestCompile to compile, the errors disappear. I created an instrumentation run config, and currently that run config is selected.
EDIT:
Here is our Gradle build file:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'realm-android'
apply plugin: 'pmd'
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:2.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
classpath 'io.realm:realm-gradle-plugin:1.0.0'
classpath 'io.fabric.tools:gradle:1.21.6'
}
configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}
repositories {
jcenter()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
// compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:support-v13:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:percent:24.0.0'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile "com.mixpanel.android:mixpanel-android:4.8.6"
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.squareup:otto:1.3.8'
compile 'com.squareup.dagger:dagger:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
compile('com.facebook.android:facebook-android-sdk:4.13.1') {
exclude module: 'bolts-android'
exclude module: 'bolts-applinks'
exclude module: 'bolts-tasks'
}
compile 'com.facebook.fresco:fresco:0.11.0'
compile 'me.relex:photodraweeview:1.0.0'
compile 'com.jakewharton.rxrelay:rxrelay:1.0.0'
compile 'com.jakewharton:butterknife:8.1.0'
apt 'com.jakewharton:butterknife-compiler:8.1.0'
compile 'com.jakewharton.timber:timber:4.0.1'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.cloudinary:cloudinary-android:1.2.2:'
compile 'com.soundcloud.android:android-crop:1.0.1#aar'
compile 'com.rockerhieu.emojicon:library:1.3.3'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'com.trello:rxlifecycle:0.5.0'
compile 'com.trello:rxlifecycle-components:0.5.0'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
compile 'com.jakewharton.rxbinding:rxbinding-recyclerview-v7:0.4.0'
compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.4.0'
compile 'com.jakewharton.rxbinding:rxbinding-design:0.4.0'
compile 'com.github.hotchemi:permissionsdispatcher:2.1.1'
apt 'com.github.hotchemi:permissionsdispatcher-processor:2.1.1'
compile 'net.sourceforge.streamsupport:streamsupport:1.4.3'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'junit:junit:4.12'
}
android {
// General configuration goes here
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
def buildNumber = computeVersionCode()
applicationId 'com.xxx.xxx'
minSdkVersion 19
targetSdkVersion 23
versionCode = buildNumber
versionName '0.2.6'
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
dexOptions {
incremental true
javaMaxHeapSize "6g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
signingConfigs {
debug {
storeFile rootProject.file('debug.keystore')
storePassword 'xxx'
keyAlias 'xxx'
keyPassword 'xxx'
}
beta {
String password = getKeyStorePassword()
println("password::$password")
if (password) {
storeFile file("beta_release.keystore")
storePassword xxx
keyAlias "xxx"
keyPassword xxx
} else {
println "Environment variable BETA_KEYSTORE_PASSWORD needs to be set"
}
}
}
buildTypes {
localDebug {
minifyEnabled false
debuggable true;
signingConfig signingConfigs.debug
buildConfigField "String", "BACKEND_ADDRESS", "\"http://xxx.xxx.dev/\""
buildConfigField "boolean", "MYVAR2", "false"
buildConfigField "String", "MYVAR3", "\"value\""
resValue "string", "BUILD_TYPE_DISPLAY", "Debug(Local)"
applicationIdSuffix ".debug"
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
lintOptions {
abortOnError true
}
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
universalApk false
}
}
}
task pmd(type: Pmd) {
ruleSetFiles = files("${project.rootDir}/pmd-ruleset.xml")
ignoreFailures = false
ruleSets = []
source 'src'
include '**/*.java'
exclude '**/gen/**'
reports {
xml.enabled = false
html.enabled = true
xml {
destination "$project.buildDir/reports/pmd/pmd.xml"
}
html {
destination "$project.buildDir/reports/pmd/pmd.html"
}
}
}
def computeVersionCode() {
def buildNumber = System.getenv('BUILD_NUMBER')
if (buildNumber == null || buildNumber.isEmpty()) {
println "No BUILD_NUMBER in environment, using 1 as revision"
return 1
}
buildNumber = buildNumber.toInteger()
println "New revision is ${buildNumber}"
return buildNumber
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:24.0.0'
force 'com.android.support:support-v4:24.0.0'
force 'com.android.support:appcompat-v7:24.0.0'
force 'com.android.support:design:24.0.0'
force 'com.android.support:recyclerview-v7:24.0.0'
}
}
I've spent about a day on this myself and finally figured it out. This is an Android Studio feature - termed a feature, but I'd consider it a bug.
To get instrumentation tests working, you need to set your Build Variants to the following:
Test Artifact: Android Instrumentation Tests
Build Variant: debug
See here for more details
I personally think is makes no sense; it's not like you're using androidTestCompileDebug, and running gradle <app_name>:dependencies repeatedly shows pulling in androidTestCompile dependencies, regardless of the build variant. But for some reason, they only resolve in debug.
I hope this helps.
I'm getting an error in Android Studio 1.5.1 and I can't figure it out for the life of me. It reads,
"Error:Execution failed for task ':app:dexguardDebug'.
No such property: bootClasspath for class: com.android.builder.core.AndroidBuilder"
When running ./gradle2 debugCompile --stacktrace from the command line, it shows this:
What went wrong:
Task 'compileDebug' is ambiguous in root project 'BestWestern'.
Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl',
'compileDebugAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk',
'compileDebugAndroidTestRenderscript',
'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac',
'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugSources',
'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources'.
I'm not exactly sure what to do from this point
Here are my grade files:
//////////////////////
// Module: app
//////////////////////
apply plugin: 'com.android.application'
apply plugin: 'dexguard'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.bestwestern.android"
minSdkVersion 14
targetSdkVersion 23
versionCode 143
versionName "5.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
/*release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
}*/
debug {
proguardFile getDefaultDexGuardFile('dexguard-debug.pro')
proguardFile 'dexguard-project.txt'
proguardFile 'proguard-project.txt'
}
release {
proguardFile getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-project.txt'
proguardFile 'proguard-project.txt'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
/*productFlavors {
}*/
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
flatDir {
dirs 'libs'
}
}
dependencies {
//compile 'com.android.support:multidex:1.0.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.google.android.gms:play-services-location:7.0.0'
compile project(':androidtimessquare')
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
//compile 'com.squareup.picasso:picasso:2.+'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'de.hdodenhof:circleimageview:1.2.2'
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
compile 'de.greenrobot:eventbus:2.4.0'
//compile(name: 'masterpass-android-library-release', ext: 'aar')
// AndroidJUnit Runner dependencies
androidTestCompile 'com.android.support:support-annotations:23.0.1'
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
// Espresso dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
compile files('libs/adobeMobileLibrary-4.6.1.jar')
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
//compile 'org.twitter4j:twitter4j-core:4.0.2'
compile('com.twitter.sdk.android:tweet-composer:0.8.0#aar') {
transitive = true;
}
compile 'com.github.bumptech.glide:glide:3.6.+'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile project(':googlemapssdkm4b_lib')
compile files('libs/RootShell.jar')
//compile files('libs/dexguard-util.jar')
}
//////////////////////
// Project:
//////////////////////
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
mavenCentral()
flatDir dirs: 'lib'
}
dependencies {
/*classpath ('com.android.tools.build:gradle:1.0.0') {
exclude module: 'proguard-gradle'
}
classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.3.1"
classpath ('net.sf.proguard:proguard-gradle:5.0') {
force = true
}*/
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:1.5.0'
classpath ':dexguard:'
}
}
allprojects {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
}
This will be most likely caused incompatible versions of Android Gradle Plugin and DexGuard library. Try to downgrade a version of Android Gradle Plugin to 1.3.1.
Could I ask which version of DexGuard are you using?