I'm working on an Android application with databinding but I've always next error:
Error: Package my.package.databinding does not exist.
Here is my build.gradle on project level:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've also enabled binding in the build.gradle file on module level.
Now my question is, why occurs this error and how could I solve it?
This problem occurs usually if your project does not compile. Android databinding should generate code in the named package, but it can't do that if the project doesn't compile in the first place.
To solve this, bring your project to a point where it compiles. If necessary, turn databinding off for this.
check out your xml files and comment any #{} you have used unless you actually have your data ready at hand. With no data, you'll bump into this error again and again and again.
I came across this issue in a project of 4 modules in Android Studio 2.3, it is what #F43nd1r indicated, but want to document what I did to resolve this in my case.
One of the 4 modules had an older Android Support library in in the Gradle file for it, while the other 3 were current. This is what prevented the project from compiling properly and causing the databinding error.
The difficult part was that you don't know about this unless you open each build.gradle file and see if there is an error displayed. It did NOT show an error for it on compile.
Effectively I updated this area to the newer version number to match the other 3 module build.gradle files.
dependencies {
...
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
...
}
To see the error, just edit these lines of code in the app's build.gradle:
dataBinding {
enabled = false
}
In this way, the last error in your build console is the actual error. Because from the first to the penultimate error, they are all related to the non-generation of the data binding classes, precisely because we have disabled it.
Once you find the error you will enter again :
dataBinding {
enabled = true
}
dataBinding {
enabled = true
}
enabled the data binding in app build.gradle file. its worked
Based on similar issues on SO, the reasons may not be related to android data binding, and instead due to incorrectly calling variables as in this issue or some other factors like in this other issue. You should provide more details if none of these links helps.
For me doesn't work anything except one: Renamed XML binding class
What I tried before:
off/on viewBinding
renaming folders
reinstalling modules
renaming modules
After deleting the build folder for the project and submodules, making, rebuilding, etc etc etc, the only thing that worked for me was:
create a new layout
I think there's something in the generator that gets messed up and that flushes it (totally guessing here)
Remember to add
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
...
buildFeatures {
viewBinding true
dataBinding true
}
}
Related
In my Project build.gradle i added these lines
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.1.1'
...
}
}
allprojects {
repositories {
...
maven {
url "https://maven.google.com"
}
...
}
}
and in my app build.gradle
dependencies {
//firebase
implementation 'com.google.firebase:firebase-ads:11.8.0'
...
}
apply plugin: 'com.google.gms.google-services'
every thing is fine, gradle sync without warning or any errors, but am not able to use any of the firebase-ads library classes i can't find them it's like i never added that dependency even i manually types com.google.android.gms. and there is no package called ads
even in .xml files i added an AdView when i press Ctrl and hover over the class name, all packages get highlighted untill gms, the ads and adView dosen't get highlighted.
i restarted Android studio,invalidate the cache, sync gradle with and without firebase-ads dependency, removed the library cache from .gradle file, nothing worked.... am i missing something?
You should also add implementation 'com.google.firebase:firebase-core:11.8.0' as a dependency. This is Firebase core dependency and should be added always.
I would recommend you to use the option from Android Studio: Tools->Firebase and then you can choose the tool you want.
the solution was to use an older version of firebase libraries '9.0.2' and it worked, thats still wierd i still want to know the real reason and if it was a bug in the libraries or Android studio to send a bug report
I am following one of the Google Codelabs for making an Instant App.
And I was trying to create topeka-ui (A UI feature module for Instant Apps).
When I try to run one of the instant app module it says :
A dependent feature was defined but no package ID was set.
You are probably missing a feature dependency in the base feature.
I had an issue in that I had an Android app and an Android Library, but I had used the wrong plugin by mistake.
For an app:
plugins {
id "com.android.application"
id "kotlin-android"
}
For a library:
plugins {
id "com.android.library"
id "kotlin-android"
}
Since this is the only stackoverflow question for "A dependent feature was defined but no package ID was set. You are probably missing a feature dependency in the base feature." I will answer what my issue was here rather than create a new question. I had a module that was giving me this error and couldn't figure out the problem. In the dependent module's build.gradle file, I had:
apply plugin: 'com.android.feature'
It should have been:
apply plugin: 'com.android.library'
I just ran through the codelab on AS 3.0 beta 2 without issues (*note). After what point in the codelab did your issue appear?
You might’ve missed a step. Double check that your base module’s build.gradle has:
dependencies {
...
application project(":topekaapk")
feature project(":topekaui")
}
Leaving out feature project(":topekaui") can cause this error:
Error:com.android.builder.internal.aapt.AaptException: A dependent
feature was defined but no package ID was set. You are probably
missing a feature dependency in the base feature.
Note: because data-binding has been disabled for non-base modules (https://issuetracker.google.com/63814741), there requires some additional steps in the multi-feature step-7 to get around it (ie. getting rid of the DataBindingUtil).
I did it in build.gradle(...mylibrary), fixed it and it worked:
plugins {
- id 'com.android.application'
+ id 'com.android.library'}
defaultConfig {
- applicationId "com.example.mylibrary"
minSdk 21
targetSdk 32}
I had this issue in my Dynamic Feature Module when I forgot to add a reference to it in the base module's android.dynamicFeatures = [":module_name"] array
Base from basic instant app project structure,
When you build your instant app, this module takes all of the features and creates Instant App APKs. It does not hold any code or resources; it contains only a build.gradle file and has the com.android.instantapp plugin applied to it. Here's an example:
apply plugin: 'com.android.instantapp'
...
dependencies {
implementation project(':base')
// if there additional features, they go here
implementation project(':feature1')
}
Furthermore, note that
The base feature module's build configuration file needs to apply the com.android.feature gradle plugin. The build.gradle file does not contain any instant app specific modifications.
With this and in line with your encountered error, you may want to check your base feature module's build configuration file. Lastly, make sure that you also sync your project with gradle files.
See Android Instant Apps documentation for more information.
With the following gradle pugin
classpath 'com.android.tools.build:gradle:3.5.1'
In my case, after adding to app's build.gradle
android{
dataBinding {
enabled = true
}
}
I got the posted error, then doing the following
Android studio -> invalidate cache and restart
Issue got fixed!
Not Fixed Yet?
Probably there is a conflicting dependency residing in build.gradle,
like the older and current version of the same library
This solution will work 100%
Step 1) Open gradle.properties
Step 2) Add android.enableJetifier=true to the file
Done!
See The Screen Shot:
You might have added dependent module as a application, it should be added as a library.
Check build.gradle file of module and
Replace
plugins {
id 'com.android.application'
to
plugins {
id 'com.android.library'
also remove applicationId from build.gradle's of inner module if its added in defaultConfig block
This is the following error I am getting while adding a new gradle dependency to my android project. And this error is not project specific. I am getting the same error if I am adding the plugin in any other android project
Error while adding any third party plugin
I also posted my project app level gradle module screenshot
App level gradle module
I even enabled Annotation Processor in the settings. Still no solution. Please help.
use this in your project gradlefile:
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
I had same issue, and problem was I forgot to add;
repositories {
maven { url 'https://jitpack.io' }
}
For those who just downloaded Android studio 3.0 update and got the :
Failed to resolve annotationProcessor
Solution: Disable the annotation processor error check
Simply copy the 'JavaCompileOptions' code block below and paste in the defaultConfig{} block.
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}
}
Ref: Disable the annotation processor error check
Well ok, now finally after struggling with this issue with annotationProcessor can't be resolved, I can tell that it is a library issue or configuration issue on your side, since you are using 3rd party plugins.
In case of library issue, it might occur in case some of magic wasn't applied to generate javadoc tasks to include javadocDepts into classpath.
Issue with configuration might be that there are custom annotations, but no custom annotation processor, or you didn't include it in dependencies as annotationProcessor 'package.name:annotationProcessorModule:version'
Anyways, I had to remove custom annotations from my own library to be able to use artifact from jcenter, otherwise I would get
Failed to resolve annotationProcessor
all the time as well, when using my library in other project.
Here's the link to my question and my repository in case it might help you if you are developing those 3rd party plugin yourself:
Can't import AAR library with #IntDef annotations
https://github.com/vulko/AnimatedArcProgressView
First of all try to clean project.
It will give you more information about the error and add the following line in your project build.gradle file.
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
then rebuild the project it should work
In our case our internal artifact server was down so it was indeed failing to resolve.
What I would recommend is running your gradle build from command line and adding the --debug parameters to it. Then you'll see lines like the following that will help you see what is failing to resolve. (Note I cut out a bunch of stuff to keep the log short here.)
[org.gradle.api.internal.artifacts.ivyservice.IvyLoggingAdaper] tried http://repo.jfrog.org/...
...
[org.apache.http.impl.conn.DefaultClientConnection] Sending request: HEAD /artifactory/...
[org.apache.http.impl.conn.DefaultClientConnection] Receiving response: HTTP/1.1 404 Not Found
I have been stuck for the past 2 days now. I want to import my own aar in one of my sample apps and then use it. I can not access the classes inside the aar and get a java.lang.NoClassDefFoundError error.
Now since this is a common problem, I have tried the below so far,after reading each and every related question:
1) Importing the aar by going to : File -> New-> New Module -> Import .JAR/.AAR
and then adding compile project(':Name-Of-Your-Project') to the gradle.
2) Using the maven plugin and pushing the aar to the local maven repo by using gradle install and then reffering to the local repo aar in my gradle.
compile ('com.rsa.mobile.sdk.android:authsdk:3.6.0-SNAPSHOT:debug#aar'){
// transitive=true
}
Note: If I uncomment the transitive=true, i get the below exception while installing the application:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
3) Rebuilding and cleaning the project as suggested in a lot of answers.
4) The only one thing which didnt work out was by putting the aar in a directory and then reffering it like compile(name:'Name-Of-Your-Project', ext:'aar') , after adding
flatDir {
dirs 'libs'
}
to the repo.
I dont think the 4th point should matter as the correct way now is as mentioned in point 1 above, but just wanted to put it out.
Can someone please help. It looks like a trivial issue but I have already wasted around 2 days.
Looking at the exception the below code can solve the problem. Add it in the application gradle.
android {
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
// FOR GC overhead
incremental true
javaMaxHeapSize "4g"
}
}
I'm using android studio 0.2.3 with gradle 0.5 and added the ormlite dependency to the build.gradle file as follows:
compile 'com.j256.ormlite:ormlite-android:4.9'
Gradle downloaded two jar files: ormlite-android.jar and ormlite-core.jar. The problem is, that the jar files contain identically named classes. So I get the following well known exception:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/j256/ormlite/dao/BaseDaoImpl$1;
Some other solution for the same problem with maven exists, suggesting to exclude the ormlite-core.jar. This should work if all classes from ormlite-core.jar are included in ormlite-android.jar - I didn't check this btw. In that case, I don't understand why the ormlite-core is in this ormlite android dependency package... I'm explicitly adding ormlite-android, as you can see in the snippet above.
But how to exclude the ormlite-core.jar in gradle. Everything I found was for gradle 1.6, but android studio uses gradle 0.5 - or is this just the version of the android gradle wrapper?
.:EDIT:.
To make the dependencies clearer, I add my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.google.android.gms:play-services:3.1.+'
compile 'com.j256.ormlite:ormlite-android:4.9'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
Why I think there are same classes in the two ormlite libs? ==> See the screenshot.
Aren't the opened packages identical? Even the source is. The only distinct classes I found were SqliteAndroidDatabaseType and those in the com.j256.ormlite.android package.
The ormlite-android jar you're using is definitely wrong. My guess is that someone built it incorrectly with ormlite-core exported, which is why you're getting the merge conflicts. If you look at the source for ormlite-android, it isn't supposed to have most of those packages/classes included.
I'm not sure how the ormlite-android versioning works, but it looks like 4.46 is the actual latest version (updated 29-Jul-2013), not 4.9 (updated 26-Jan-2011). I'd recommend using 4.46 instead (that's what works for me) with:
'com.j256.ormlite:ormlite-android:4.46'
Thanks to #cproinger for the answer in another related question.
WOW, now it works! I misunderstood the versioning (my fault). But anyway, the newer version (4.46) contains only the android specific classes in the ormlite-android.jar and everything else in the ormlite-core.jar. Great, thanks #cproinger!