I had a working project in Android-Studio, including Databinding. That eleminates some possible sources of error. ;-)
Then I decided to get my feet wet with Kotlin and began to migrate some classes from Java to Kotlin.
Unfortunately I also klicked to update Android-Studio to 3.4 in the middle of this process. So now I have many moving parts ...
Now after some editing, when I try to compile my app, the databinding-classes are not generated any more. Usually this is a problem of missing getters or setters or something like this. But currently I have no compiler errors that indicate such problems. Only all the references to my BR. class are red as this class is not generated.
In the layout-files the getters and setters from the data-variable are not shown - so there is a problem already there.
The build-log tells me to check the log for details, but I can not find any log with error-messages that could lead to a solution.
Android-Studio 3.4, mixed Java/Kotlin sourcecode
Besides those missing BR class, I have no other compilation errors at the moment.
I checked the raw gradle output and also tried to run those steps with the more verbose output - no luck.
Maybe this is related:
- I also have problems to edit my existing layouts with constraint-views. Somehow the constraints are read-only.
After some fiddeling around I managed to get one layout back to read-write mode. Not shure what I did to accomplish this ...
- Also I have the problem that Android-Studio "remembers" the last project and mixes the configurations from the last project with that of the current one. To fix this I have to delete the .idea folder in the project ... After that I can work with my project until I change to another or open a second one in parallel ... :-/
In order to get logs I also changed to generate the binding-classes by the compiler instead on the fly by Android-Studio - no luck.
As this is an installation with some history, I also tried to delete the configuration-files from Android-Studio - also no luck.
Clean- and Rebuild Project, Restart Android-Studio, Invalidate Caches ... all that tried without success.
Currently I am out of ideas where to look. Maybe somebody out there has a tip for me?
if you use imports in xml like
<import type="java.lang.Integer"/>
you have to delete it because android studio is imported automatically.
ref :
Just as in managed code, java.lang.* is imported automatically.
Finally I found the source of my problems!
After many attempts to find an error in my code or maybe in Android-Studio (also downgraded to 3.3 and tried the current 3.5 canary version) I decided to strip down the code to the max.
So I created a new project. In that project I created 2 observable classes and copied the minimal code from https://developer.android.com/topic/libraries/data-binding/observability#observable_objects.
I created one class in java and one class in Kotlin (with an index-Number at the properties so that I could see which properties are generated in the BR class).
Only the properties from the Java-class were generated in the BR class, those from the Kotlin class were missing. No error messages besides the missing BR-properties were generated. :-(
With this information I started a new research and finally found, that for Kotlin currently the apply plugin: 'kotlin-kapt' was missing in the project build.gradle file.
Once I added this, also the properties from the Kotlin class were added to the BR class.
Some (older) articles also add kapt "com.android.databinding:compiler:x.x.x" to the dependencies, but with the latest compiler I got null-pointer exceptions. Seems that this component is already referenced somewhere else, because it is not necessary (any more).
I also added this to my other project and now those BR-properties are also present there. So I am confident to have found the answer to my question and can now focus on bugfixing my app.
Related
I have an Android project (I'll update soon with the source once public) that has code in Kotlin.
When I try to import a class it shows on the auto-complete but then it does a full name reference instead of adding the reference to the class on the imports of the file. Also, when I try to do an import, there is no option to include the import to the class.
It's happened so far in two projects I've worked on. The first one had a mix of Java a Kotlin and I thought that may be the issue, however, the last one doesn't have any Java code.
The code is in the debug configuration. However, a file that is on the same package and folder as this one with the issue doesn't seem to have the same problem and imports work as expected.
Update after duplication suggestion
This was marked as a duplicate, but it's not for several reasons:
This one involves Kotlin and not Java
The reported problem was with project imports, this is a library (system) import
Tried the suggested solution and it doesn't solve this issue.
This one has a gif ^_^
Best what you can do it build new Empty Project and copy old classes and files on new project.
I'm trying to generate NSManagedModels from my datamodel. Generation works but after I got many errors :
error: filename "Station+CoreDataProperties.swift" used twice:
'/Users/Me/MyApp/Models/CoreData/Station+CoreDataProperties.swift' and
'/Users/Me/Library/Developer/Xcode/DerivedData/MyApp-gwacspwrsnabomertjnqfbuhjvwc/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/DerivedSources/CoreDataGenerated/Model/Station+CoreDataProperties.swift'
:0: note: filenames are used to distinguish private
declarations with the same name
I try clean build folder and derivedData directory hard delete. I'm using Xcode 8 BETA maybe it's a bug ?
I get this in Xcode 8.1
For me following steps solved the issue. Please note that order matters.
1) Create entity in Core Data model.
2) Under class section, make settings as on following image.
Module: Current Product Name
Codegen: Manual/None
3) Generate your NSManagedObject subclass.
This post greatly helped me solve this problem myself. Personally I look at this as an Xcode bug. Bug or not this is a huge chicken and egg situation.
I ran into this by:
Created a new Project using Core Data
Generated my NSManagedObject subclass+extension (while codegen: ClassDefinition)
I accidentally saved the generated classes in the Wrong folder
I deleted the generated files
Re-generated in folder I wanted
đź’Ą- Xcode used twice errors
As others have posted I kept cleaning my build (and clean build folder) but that never fixed the build issue.
I finally figured out if you originally created your NSManagedObject generated classes with codegen: ClassDefinition, as I did without knowing then you are locked in for the chicken and egg issue.
I then deleted the auto generated classes thinking I had to re-generate, so I did. Once re-generated I would get the used twice build error again. I manually went into the ../DerivedSources/CoreDataGenerated/Model/.. and deleted the duplicates. Again, I re-generated thinking I'd only have 1 copy (in my project) but I was wrong. If codegen: ClassDefinition was originally set then Xcode will keep creating the auto-generated classes+extensions and put them in the buried folder ../DerivedSources/CoreDataGenerated/Model/... I repeated this chicken and egg a few times before catching on.
I later realized you do indeed need to mark codegen: Manual/None however to get things back in sync you need to delete the auto-generated files in ../DerivedSources/CoreDataGenerated/Model/.. and in your project if you have any there still.
Be careful setting codegen: Manual/None, for me it was bit tricky because codegen: Manual/None wouldn't stick. I had to click back and forth between entities multiple times to double/triple check each entity was set to codegen: Manual/None. Then auto generate the files. At this point your only copy of the auto generated files should be in your project and not in ../DerivedSources/CoreDataGenerated/Model/...
Last, I think this is a bug because if you specify codegen: Manual/None I don't expect Xcode to auto generate files at all, yet it does and puts them in your project. More confusing if your setting is codegen: ClassDefinition, who the heck knows Xcode will put the files in a buried directory yet it is available for use in your project. My beef with this is the auto generated files aren't source controlled and if I change computer I have to know to auto-generate them on the new station.
Hope this helps someone else!
Cheers!
This is indeed not a bug. As #Morrowless suggests both class definition and properties extension are created. If this is not wanted, select Manual/None under Codegen before generating the code. If the code is already generated, just delete them, and try Editor->Create NSManagedObject Subclass... again from the menu (after setting Manual/None).
Note, in the picture below, the Class Name 'Contact' is specific to my project. You will see your entity name instead.
If you generated CoreData subclasses with codegen: ClassDefinition your basically screwed. The only way to fix it is to:
Delete your CoreData subclasses.
Delete your derived data folder.
Clean your project (CMD+K).
Generate new CoreData subclasses, this time select Codegen: Manual/None and Module: Current Product Module
This is not a bug. Codegen generates these files in the DerivedData folder, so you don't need to create them again in your project, hence the compile error.
From Xcode 8.0 Release notes:
Xcode automatically generates classes or class extensions for the entities and properties in a Core Data data model. Automatic code generation is enabled and disabled on an entity by entity basis, and is enabled for all entities in new models that use the Xcode 8 file format. This feature is available for any data model that has been upgraded to the Xcode 8 format. You specify whether Xcode generates Swift or Objective-C code for a data model using the data model’s file inspector.
When automatic code generation is enabled for an entity, Xcode creates
either a class or class extension for the entity as specified in the
entity's inspector: the specified class name is used and the sources
are placed in the project’s Derived Data. For both Swift and
Objective-C, these classes are directly usable from the project’s
code. For Objective-C, an additional header file is created for all
generated entities in your model. The header file name conforms to the
naming convention “DataModelName+CoreDataModel.h”.
However, if you selected Category/Extension under the codegen pulldown menu in the data model inspector (because you want to add logic to your model): codegen will wrongly generate both the class definition and properties extension.
The solution is to simply delete the properties extension (ClassName+CoreDataProperties.swift). Your project should now compile.
After following the guidance from oyalhi and Vladimir Shutyuk, (deleting the NSManagedObject files, changing the entity codegen to Manual/None), I had to restart Xcode to allow it to index again before I could re-generate the NSManagedObject files and get a successful compile.
For the sake of completeness..:
I just ran into the same error, but none of the proposed solutions worked. What puzzled me was that even switching from automated code generation to manual for the one (as I thought) problematic entity didn't do anything.
Finally, I figured out that I had several entities with the same name, but they all shared the same classname. The reason for this was that I copy&pasted one entity several times to save me some work, because they also have a few attributes in common.
Turns out XCode renames the duplicates by adding 1, 2,... to the entity name, but leaves the class name as before. And since now entity name and class name are "unrelated", renaming the entity won't change the class name either.
Hope it helps someone - I have also filed a bug report for this.
I am trying to do a small test project using ActionBarSherlock library but having the same issue as in this post -> android-support-v7-appcompat has same attrs as actionbarsherlock library
Ref: http://pastebin.com/ERDHsQbe
Has anyone found a solution yet?
Thanks.
remove support-v7-appcompat library from your project, its in build with sherlock .
Then in the styles.xml change parent="Theme.AppCompat.Light" to
parent="android:Theme.Light" .This will be sufficient .
If you are gettin any errors related to android-support-v4 , try and copy the latest android-support-v4 into the Sherlock library folder in your workspace.
I have the same problem since I changed attributes in attr.xml file which is identical to another attributes in support-v7-appcompat library
and changing every thing related to it in the actionbarshelock project manually
I lost much of time but finally I did it
replace your ActionBarSherlock library by this one
https://drive.google.com/file/d/0B-XiEeIClMuTb2t3S0h0d2lsUUE/view?usp=sharing
the only change is in the attr.xml file and it's reflection on the java code and layouts
note : you must be sure that you have only one android-support-v4 library file to avoid jar mismatch
I'm trying to get chromecast integration in my app but I'm having build issues when I add the android-support-v7-appcompat to my project. Basically it has an attrs.xml file that has the same values as the actionbarsherlock attrs.xml file. Is there anyway around this? This seems kind of ridiculous that different libraries can possibly conflict resource values.
I just encounter the same problem and had a hard time for several hours figuring this out. this is how I solved it.
You usually need support-v7-appcompat if your minimum sdk supported is below API14.
I removed support-v7-appcompat as my library. (This will show error regarding missing theme.)
For all the styles.xml in all folders (mine are) values, values-v11 and values-v14
style name="AppBaseTheme" parent="Theme.AppCompat.Light"
replace it with
style name="AppBaseTheme" parent="android:Theme.Light"
for some reason, in my menu xml file. it had error for android:showAsAction. I was able to solve it by deleting it then save and then copying the same thing from another file i have because I want that function. (Really weird it was just the same text.)
I did my sherlock code adjustments needed for my app
I am now able to run actionbar in 2.3.3
In my project I have a class that is inherited by many other classes. We'll call it ClassBase.
public class ClassInheritFromBase : ClassBase
When ClassBase is being inherited, ReSharper throws an "Ambiguous reference" warning on the ClassBase, and anything inside the new class that inherited from ClassBase does not have IntelliSense and gets warnings that it cannot find it.
The project compiles and runs fine.
If I change the namespace ClassBase is in and then change the inheriting classes, they find it fine and ReSharper has no problem, IntelliSense works ... until it is compiled. After the compile it goes back to having the ambiguous reference warnings and everything else.
Has this been seen before and how can it be fixed? I saw an entry in JetBrains bug tracking for an issue just like this, but they closed it as unable to reproduce.
For those who still have a problem with this, (I still get it from time to time) here's the steps I did to get rid of the ambiguous reference warning in ReSharper.
First I went to all my class libraries and made sure that all references to my other class libraries had the Copy Local property set to false.
In the project where I actually got the ambiguous reference warning, I went to my bin catalog and deleted all .dll and .pdb files for all the libraries that had their own project.
After a new build, or in my case "update reference" on the .dll files in VS, the errors from Resharper were gone.
I'm using Resharper 5.1 in Visual Studio 2008 with only a reference to the dlls I'm using which is why I had to "update reference"
I'm using VS 2012 and ReSharper 7 and sometimes I found the same behavior. These are the steps that worked for me:
Clean Solution
Close Visual Studio
Go to the root folder of your solution and find a folder called _ReSharper.[Name of your solution] and delete it.
Go back to Visual Studio, open up your solution the folder gets recreated and no more "ambiguous reference" errors after that.
I've seen this bug in ReSharper 4.1. It happens when the base class is in the App_Code directory. I don't know how to fix it; it is very annoying, but the code still compiles though.
You may really have an ambiguous reference. In the project where the ambiguous reference error occurs, make sure to check in your project references. You might have the same reference twice but scoped through different namespaces. In my case there were two, but with different paths (example):
XXX.YYY.ZZZ.myassembly
ZZZ.myassembly
Make sure you don't have this kind of thing in your references.
This is a bug in ReSharper 4.1 and is fixed in one of the later nightly builds.
Download the last nightly build at
http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.0+Nightly+Builds.
ReSharper -> Options -> General: Click # Clear Caches # button.
For me it was a matter of me not using the solution folder for caches. Changing it from the TEMP location to in the solution solved my problem.
I deleted the _ReSharper.SolutionName folder found in the root of my solution and restarted.
I was using Visual Studio 2010 with ReSharper 5.1... Clearing the cache DID NOT help (ReSharper -> menu Options -> General -> #Clear Cache#).
With R# 2019.2.3 and using the new SDK .csproj format, which splits references between .NET references, NUGET packages, and project dependencies, there is a tendency for R# to still add a project reference under Assemblies, even when there is already a project reference under Dependencies. This results in the ambiguity error but can be hard to notice since the reference is in two separate places. Look for any project references that appear under Assemblies and remove them.
I was experiencing the same problem with references to C# classes in the AppCode folder.
I resolved this by upgrading my ReSharper to version 4.5 (from version 4.1).
It was a very simple upgrade, I just had to get the latest version from the JetBrains website (http://www.jetbrains.com/resharper/download/) and run it.
I did not have to uninstall the previous version (v4.1).
I did not have to re-enter my existing licence key.
All references are now recognised correctly and I can naviage to the classes as expected.
I encountered the same problem. The issue I had was caused by a custom build provider (from an open source library I'm using called PageMethods) and the fact that all my .aspx pages inherit from a BasePage class which lives in the App_Code folder.
I couldn't get any build of ReSharper to work with my project (4.1.933, 4.1.943 (latest) or 4.5). The fix in the latest ReSharper build fixes the "Ambiguous Reference" problem, but breaks the custom build provider.
The only way I could get both the build provider and base classes to work with ReSharper was to put the Base Classes into a separate class library.
The following are the logged Jira bugs that seem to relate to this issue:
False "Ambiguous reference" for
symbols from App_Code
Custom build provider may generate partial
class with second part residing in
app_code
I had same problem with ReSharper 5.1 and solved it by restarting Visual Studio 2010.
Using VS 2013 Premium & Resharper 8.1, and was getting this problem on an ASP.Net project.
The solution that worked for me:
Do a clean Solution.
Open references for the offending project
On each reference that refers to another project in the solution, set Copy Local = false.
Attempt a Rebuild Solution. You will likely get unresolved reference errors - that's normal.
Set each reference back to Copy Local = true (where appropriate)
In VS2022, simply cleaning the solution resolved the errors for me.