I have seen and used compile, compile files, androidTestCompile etc for importing dependencies in my android project. Today I came across embedded in the gradle of an existing android project. Not sure what this means. Even googling didn't help me on this. Can anyone please help. Below is the line I saw in the build.gradle file.
embedded 'com.eyeverify:EVServiceInterface:2.6.1-release#aar'
The keyword embedded doesn't exist in Gradle syntax. I think in that android project, embedded was a custom configuration defined in a build.gradle file:
configurations {
embedded
}
So you can use:
embedded 'com.eyeverify:EVServiceInterface:2.6.1-release#aar'
Related
I'm pretty new to android studio, but i got this error and i can't run my project. I saw a lot of answers which suggest to add the support-annotations dependency, but I'm using appcompat so i don't need that. Any thoughts?
Do you have the Android Support Library?
To do it add this to your build.gradle file of the "app" module:
dependencies {
...
implementation "com.android.support:support-annotations:27.1.0"
}
Then sync the project.
Sometimes you can do this automatically by pressing Alt+Enter over the error message and selecting the solution.
You need to fetch the libraries that contain the imports, in your build gradle file of your module add the line inside dependencies tag:
api 'com.android.support:support-annotations:X.X.X'
or
implementation 'com.android.support:support-annotations:X.X.X'
Where X.X.X is the version of the rest of your support libraries.
You should read this article that explains how to implement this with more detail.
I have an Android project with the following dependencies:
-- Android App
---> MySDK.Jar
------> 'org.apache.commons:commons-lang3:3.5'
This is MySDK.jar that has a dependency on commons-lang3.
I'm working on Android Studio and I'm thus using Gradle.
Here is my problem:
I have shared "MySDK.Jar" to someone and he has built his own Android App on top of it.
It works but we have seen that the compiler doesn't notice the missing dependency on 'org.apache.commons:commons-lang3:3.5'. At run-time there will be a crash if the code using 'org.apache.commons:commons-lang3:3.5' is called. One may not notice the problem if he doesn't call the code using this library.
I know that we can solve this issue by adding the following line to Android App build.gradle file:
compile 'org.apache.commons:commons-lang3:3.5'
I'm wondering if there is a way to get a compile error indicating such missing dependencies? It is indeed better to see the dependency problem at compilation time rather than at runtime.
What are the recommended good practices for this?
Thanks!
commons-lang3 is a transitive dependency of Android App. As such, it is often not needed for compilation - there are exceptions, especially regarding multiple levels of inheritance. So at compile time you (usually) do not know whether you miss a transitive dependency that you need at runtime.
This is where Gradle comes in. Gradle can (as Maven) resolve dependencies transitively from a Maven repository (as MavenCentral). If you put MySDK into a Maven repository (like Nexus or Artifactory, which have open source versions), everyone using MySDK will automatically draw commons-lang3 so you will not miss anything at runtime.
If you are just adding the jar file in your project you can't warning about the missing dependencies.
To do it you have to publish the jar file in a maven repo.
In this way you have a pom file which describes the dependencies that gradle has to download.
Provide a method like MySDK.init() int your MySDK.jar,call a method whe is belong to org.apache.commons:commons-lang3:3.5' in the MySDK.init() method, then put init() into onCreate() of your Application,
Another way is,putorg.apache.commons:commons-lang3:3.5 into MySDK.jar,
Hope it helps you :)
I am building an Android Library that I am trying to publish to a Nexus Maven Repository. What leaves me puzzled is that there seems to be no clean way of publishing my project through gradle with the maven-publish plugin.
I found a number of answers, which don't really satisfy me:
This plugin only works okay-ish and it is not currently maintained.
Modifying the generated POM in my build.gradle works, I just don't feel like this is the way it should be done - it seems to common of a problem to be solved in each and every android library's build.gradle.
Google even mentions the maven-publish plugin in their documentation but they don't really show how to use it.
Please tell me what I am missing: Is the problem less trivial than I think? I am just trying to publish an AAR with a pom stating it's dependency, I am trying to build the most standard and default solution I can.
Thanks in advance.
I have a library project used by my project. Also my project has several build flavors. In code I reference some classes from that library. I need that library to be removed from my .apk for some of the flavors. I know that this will lead to NoClassDefFoundError but it's ok for me.
I tried to use flavorCompiletask instead of compile but this were leading to errors during compilation of my project (as expected). So how can I make that libeaey project present during compilation but removed from .apk?
P.S. I know that I can remove it during compilation AND alter some of the code files which are using the classes from that library but for me NoClassDefFoundError is ok so I'd like to not have different versions of the same .java files per flavor.
EDIT1
I've found this article but Gradle version seems to be older then current one. Also now I know that I'm looking fot ability to add compile time dependencies.
you could add flavour specific compile block in dependencies, so ex. if you have flavour free and pay
use
dependencies {
payCompile '<something>'
}
you might use provided:
dependencies {
provided 'optional-lib'
}
In my project, i have a module abc:
//abc module (lib) dependency
dependencies {
compile 'com.android.support:support-v4:21.0.3'
}
And my app's dependency:
dependencies {
compile project(':abc')
}
And the errors are:
“Attribute ”mnp“ has already been defined”
“Attribute ”xyz“ has already been defined”
...
And i found that all these attributes are defined in declare-styleable of module abc and they are quite a lot. I dont know where they produce the duplicate since i can run normally from Eclipse, not Android Studio. Some suggests that to manually rename the attributes of those but I think it is time consuming.
Any better solution? Thank you!
This happens to me as well when I import project from Eclipse. Android Studio seems to binds library project even thou there was an error adding library modules.
I can usually fix this by firstly delete library modules, then opening Project's settings.gradle file and delete imports from there. After this, import of library modules works well.
And when I have issues with styleable file, I can usually fix this by setting SDK version to at least 20 (Android 5.0)