I have seen the following different ways of writing the dependencies in Gradle:
implementation("com.squareup.okhttp3:okhttp:3.12.0")
and
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
and
compile 'com.squareup.okhttp3:okhttp:3.12.0'
Are they all different ways to accomplish the same thing or are there differences among them?
build.gradle files are just Groovy scripts. So its syntax applies here
In Groovy, you can ignore the parenthesis when invoking a function so
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
is actually equivalent to
implementation('com.squareup.okhttp3:okhttp:3.12.0')
In Groovy you also have GStrings which are represented by ". They contains embedded Strings. In that particular case you're not interpolating any value so both
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
and
implementation "com.squareup.okhttp3:okhttp:3.12.0"
are equivalent. Beware that if you wanted to interpolate some value you'd do
implementation "com.squareup.okhttp3:okhttp:$okhttpVersion" // this line works
implementation 'com.squareup.okhttp3:okhttp:$okhttpVersion' // this line doesn't work
compile method for defining dependencies is deprecated in favor of implementation and api. You can find more info here. You can consider that if you're exposing somehow the classes of your dependencies you'll use api but if you're using the dependencies internally implementation is fine
the compile configuration is deprecated and is replaced by implementation or api.
Related
Trying to integrate instant search in my Android app, but "Searcher" is unresolved.
I have the following dependencies currently, am I missing any?
implementation "com.algolia:algoliasearch-android:3.27.0"
implementation "com.algolia:algoliasearch-client-kotlin-jvm:1.0.0"
implementation 'com.algolia:instantsearch-androidx:1.15.2'
implementation "io.ktor:ktor-client-android:1.2.2"
include core dependency also
implementation 'com.algolia:instantsearch-androidx-core:1.15.2'
The latest release of instantsearch-androidx is lacking its transitive dependencies. The issue was reported on GitHub, you can follow its progress there - likely a new version will soon be released with the appropriate dependencies packaged.
As a workaround, you can add the dependencies yourself to your application - depending on the InstantSearch features you use, you might need some or all of the following:
implementation "com.algolia:instantsearch-androidx:$VERSION_INSTANTSEARCH"
implementation "com.algolia:instantsearch-androidx-core:$VERSION_INSTANTSEARCH"
implementation 'com.algolia:algoliasearch-android:3.27.0'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
I have created by own library for helper methods & classes also included few other dependencies, then used the jitpack to create a custom dependency. But after implementing it to a project, the classes using the other dependencies are not visible to android studio.
I tried adding the other specific dependencies to the project and it works but I need to find alternative way without the need of adding specific dependencies. If it is possible, please do help.
My Library: My-Utility
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.android.gms:play-services-location:16.0.0'
If you are expecting any of those implementation dependencies to be automatically visible to apps using your library, replace implementation with api.
See the documentation for more.
When I connect to Firebase Auth I got error in dependencies check this screen shot. How to fix this error?
You need to override the clashing support libraries by adding the conflicted libraries explicitly in your dependencies block.
dependencies {
implementation "com.android.support:support-media-compat:28.0.0"
implementation "com.android.support:animated-vector-drawable:28.0.0"
}
or you can use the whole support-v4 library which is include all the above libraries:
dependencies {
implementation "com.android.support:support-v4:28.0.0"
}
The message is self explanatory, you are using different versions for each of the following.
implementation 'com.android.support:support-media-compat:26.1.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
Change any one to match another, usually upgrading is better choice.
The docs mention that implementation provides significant build time improvements over compile/api. What about compileOnly?
My use case is a multi-module (sorry I don't like Gradle's multi-project terminology) project, where I have an Android app, and multiple libraries that the app depends on (implementation). Some of the libraries also depend on one another. Should I use implementation or compileOnly when declaring dependencies in the library modules? My app module will be using implementation to depend on those artifacts, so I don't need them to be transitive through the library modules.
The api configuration should be used for dependencies that are exported to external modules (transitive dependency). Vice-Versa implementation configuration should be used for dependencies that are internal to the component (not transitive dependency).
implementation vs compileOnly:
There is no similarity in their job, compileOnly is
a configuration inherited from java-plugin
required at compile time
also not included in the runtime classpath or exposed to dependent
projects.
So compileOnly doesn't replace the implementation configuration job e.g:
implementation 'com.android.support:appcompat-v7:25.1.0' // can't use compileOnly here
testCompile 'junit:junit:4.12'
compile "com.google.dagger:dagger:2.8" // can't use here also
annotationProcessor "com.google.dagger:dagger-compiler:2.8" // can't use here also
compileOnly 'javax.annotation:jsr250-api:1.0' // we can use compileOnly here because it's required on run time only.
Since your case is a "multi-module", you have to use the api configuration, until you reach the final module it's better to use implementation.
Following graph describe those configurations:
Performance?
I think api requires more memory because gradle will snapshot every class in that transitive module, vice versa implementation is a preferred configuration because (as mentioned above) it's used for its own internal implementations.
I am using Android Room Persistence library (v.1.0.0-alpha1) in my app.
Although it is working fine, when I open model class (Kotlin Data class) in Android studio, it shows Unresolved reference for all annotations used for Room database like #Entity, #ColumnInfo etc. I tried changing version of arch library to 1.0.0-alpha5 but result was same.
In Lint inspection it is showing Remove deprecated symbol import for all imported annotations.AS was not showing this error previously.
How can I resolve this issue
Edit
Following are imports I have added in my build.gradle
compile "android.arch.persistence.room:runtime:1.0.0-alpha5"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha5"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha5"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha5"
Here you have an example.
https://github.com/jsperk/PocRoom
Remember, you need add:
Gradle (Project)--> maven
Gradle (Module App) dependencies -->
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
testImplementation "android.arch.persistence.room:testing:1.0.0"
implementation "android.arch.persistence.room:rxjava2:1.0.0"
In my project, I have this question cause I'm using
android.arch.lifecycle:livedata:1.1.1
than no matter using room with version 1.1.1 or 1.0.0, it still can't find the android.arch.persistence.room.Entity.
I've searched for a long time, till I found that, when I delete the LiveData implementation, the problem solved. Then I notice that, the version of these two libraries conflict. At last, I use the same version of 1.1.0 for livedata and room (since livedata have no version of 1.0.0), and solved it.
def arch_version = "1.1.0"
implementation "android.arch.persistence.room:runtime:$arch_version"
annotationProcessor "android.arch.persistence.room:compiler:$arch_version"
implementation "android.arch.persistence.room:rxjava2:$arch_version"
implementation "android.arch.persistence.room:common:$arch_version"
implementation "android.arch.lifecycle:livedata:$arch_version"
implementation "android.arch.lifecycle:extensions:$arch_version"
Adding these dependencies to your Gradle(Module App) file will solve it:-
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
testImplementation "android.arch.persistence.room:testing:1.1.1"
implementation "android.arch.persistence.room:rxjava2:1.1.1"