"provided" scope not working - android studio with gradle - android

I need to prevent gradle from exporting a certain shared library.
I´ve read that using the provided scope should do the trick, but it seems that it was only working with older gradle versions.
Is there any other way to exclude dependencies from the build process to not get them into the final apk?

I have found solution here: https://stackoverflow.com/a/10406184/310760
But for Gradle 2.0 it has small changes:
configurations{
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
test {
compileClasspath += configurations.provided
}
}
sourceSets.main.compileClasspath += configurations.provided
idea {
module{
scopes.PROVIDED.plus += [configurations.provided] // for Gradle 2.0
}
}

I have the same problem, and I found some solutions.But I don't understand.
http://www.sinking.in/blog/provided-scope-in-gradle/

Solved thie problem by using the android-apt gradle plugin.
see https://bitbucket.org/hvisser/android-apt/overview
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "org.ligboy.test.card.module1"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
configurations {
apt
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
apt 'com.android.support:support-v4:21.+'
apt 'com.google.code.gson:gson:2.2.+'
apt 'com.android.support:cardview-v7:+'
apt 'com.android.support:recyclerview-v7:+'
}

Fought with this for a while and found:
"provided" is part of gradle 1.3.0, but doesn't work properly.
"provided" works properly in gradle 1.5.0!
FYI: I had to delete my build directory after upgrading to 1.5.0 to remove the lib file from the .aar.

Related

Data binding cannot be added to my project

In my Android project, I have needed to enable the dataBinding library in module level build.gradle as below, but it gives me the error in the image. How can resolve it?
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.nasser.studio.multipledeletelistview"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding{
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.codesgood:justifiedtextview:1.0.2'
}
Edit 1.
I've changed the project level build.gradle to add support-v4 library, but now it throws the following error:
repositories {
google()
jcenter()
configurations.all {
resolutionStrategy.force "com.android.support:support-v4:27.0.2"
}
}
one of your 3rd party libraries or sdk you use rely on support version 21.0.3. Either remove it or have resolutionStrategy in your Gradle.
configurations.all {
resolutionStrategy {
force ....
}
}
Try upgrade your android gradle plugin.
Add compile "com.android.support:support-v4:27.0.2" manually to your gradle file.
That should solve your problem.
That's not a Databinding error, It's just saying that all your support-related libraries should use the same version. For example look at my gradle file:
implementation "com.android.support:recyclerview-v7:$libraries.googleSupportVersion"
implementation "com.android.support:appcompat-v7:$libraries.googleSupportVersion"
implementation "com.android.support:support-v13:$libraries.googleSupportVersion"
implementation "com.android.support:design:$libraries.googleSupportVersion"
implementation "com.android.support:cardview-v7:$libraries.googleSupportVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
My support library version being:
ext.libraries = [
...
googleSupportVersion : '27.1.1',
...
]
Your issue seems to be that compile 'com.codesgood:justifiedtextview:1.0.2' internally is using the support library with a version different than yours. However your version is totally updated I wouldn't downgrade it just to have it match with the other, in any case you could just add a:
allprojects {
configurations.all {
resolutionStrategy.force "com.android.support:support-v4:27.0.2"
}
}
In your project gradle. You could also run gradlew app:dependencies in the Android Studio console, do a Ctrl+F on the output, search for that com.android.support:support-v4:27.0.2 and figure out from where is coming. (You only have one dependency for what I see, so there's not much science from where IT should be coming)
Let me know if this works for you.

Module inclusion: not intended for consumption by other components - gradle:3.0.0-alpha2

Upgraded to:
Android Studio 3.0 Canary 2
com.android.tools.build:gradle:3.0.0-alpha2
I have a multi-module project (main app + sub modules)
Inclusion inside the main app:
dependencies {
implementation project(path: ':testlib', configuration: 'default')
}
The testlib is defined as a simple android library project and works normally when included with gradle 2.3.0 and via compile project(path: ':testlib')
I get the following gradle error message:
Could not resolve all dependencies for configuration ':app:devDebug_signedCompileClasspath'.
Selected configuration 'default' on 'project :testlib'
but it can't be used as a project dependency because
it isn't intended for consumption by other components.
What does "isn't intended for consumption by other components" mean in this context? The module is defined as an android library.
Here is the build.gradle of the testlib:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
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(dir: 'libs', include: ['*.jar'])
}
What am I missing?
I also got this error. Android Studio 3.0 Canary 4 just came out. I updated to it, which also updates gradle to 4.0rc1.
The problem went away on it's own.
alter your Top-level build file (aka root gradle)
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
still not working?
update dist-url (inside gradle-wrapper.properties)
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-rc-1-all.zip

How to implement Robobinding in android app

I'm trying to implement the MVVM architecture using Robobinding. Here's the link I'm following for the Environment setup of Robobinding in Android Studio(without AspectJ):
http://robobinding.github.io/RoboBinding/getting_started.html#_android_studio
This is what my app level Build.gradle looks like after adding the dependencies:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.simpletimerapp"
minSdkVersion 14
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.1.1'
compile "org.robobinding:robobinding:${robobindingVersion}"
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
}
}
The problem is gradle build fails with the following error:
Error:(26, 0) Could not find property 'robobindingVersion' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#2ccd2d42.
Open File
EDIT 1:
On replacing ${robobindingVersion} in the dependencies block with 0.8.12 (latest version of robobinding), gradle build finishes successfully. But now, I'm unable to use the "bind" attribute in the views in my layout files. This is the error:
Unexpected namespace prefix "bind" found for tag TextView
EDIT 2:
Still can't find the solution. So, I downloaded this minimal android app (from their official github page) which implements robobinding and edited it to create my own app. It's working fine now.

Android Studio: How to see sources for android support v4 and v7?

In Android Studio support library appcompat (for ActionBar) is defined as Gradle dependency.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
That resolves to get v4 as well.
How to see source when clicking to into classes?
e.g. android.support.v4.widget.DrawerLayout
Currently Android Studio says
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
For ADT it was How to add source + javadoc for android-support-v7?
Following from the above research done by Paul Verest...
IDE: Android studio 1.3.2
It is a 2-step process: Consider this sample build.gradle
1) Add the following to your build.gradle (Module:app) - search the 2 //Add comments below.
apply plugin: 'com.android.application'
apply plugin: 'idea' //Add
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.android.myapp"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.0'
}
//Add
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
2) Rebuild project.
After this point if you want to see source in Android Studio, it will pull up the source *.java instead of decompiled *.class
Thanks to Setu for hint. As I already had all sources before, I just added in app/build.gradle
apply plugin: 'idea'
idea {
module{
sourceDirs += file("E:\\Android\\sdk\\extras\\android\\support\\v4\\src\\")
sourceDirs += file("E:\\Android\\sources\\platform_frameworks_support\\v7\\appcompat\\src")
}
}
below dependencies section and press "Sync project with Gradle Files"

AndroidAnnotations error in Android Studio

I have been using AndriodAnnotations with Eclipse (ADT) without any issue. Recently, I decided to explore Android Studio. Using Android Studio with AndroidAnnotations has a few issues when I build the app. Below is the error:
I can run the app without any issues when it is showing three errors.
Below is my build.gradle:
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.test.restaurantmenu"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apt {
arguments {
androidManifestFile variant.processResources.manifestFile
resourcePackageName "com.test.restaurantmenu"
}
}
dependencies {
apt "org.androidannotations:androidannotations:3.0+"
compile "org.androidannotations:androidannotations-api:3.0+"
compile 'com.android.support:appcompat-v7:+'
compile 'com.github.satyan:sugar:1.3'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I've enabled the annotation processors as follow:
Is there any steps I missed or wrong in my setup?
I installed "Android SDK Tools 23.0.2" and all the errors were solved.
if you're using kotlin and you're getting an error showing
error: annotations are not supported in -source 1.3 (use -source 5 or
higher to enable annotations)
There is a workaround for it
Open Project Structure (File -> Project Structure). Select the module.
Change the source compatibility and Target compatibility from kotlin 1.3
to jdk 1.8

Categories

Resources