Every change to a kotlin file results in a Redeclaration error when building. The only way around it is by cleaning the project and then rebuilding. There are no other files in the project with the same name as the files I am editing.
I have tried:
The current build is using:
org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21 com.android.tools.build:gradle:3.2.0
Example code that will cause the error. If I build without the addedThisLine
it works as its the first build. Then when I edit the file in anyway it will cause the error below.
package beagle.com class ErrorFragment { val hello = "Hello" init { var goodbye = "goodbye" var addedThisLine = "When this line is added I get error" } }
Error I get
This happens in every kotlin file in my project, the code I posted above is the most basic file. As you can see it points to the name of the class for the error.
just clean project and rebuild your project again
TL;DR: Check your directories have the exact same name as they appear in settings.gradle
.
Worth to mention: MacOS is not always case sensitive and that can lead to weird problems.
I think I find a solution: Case sensitive stuff.
In my case I'm using modules, let's just call the modules: moduleA
, moduleB
In settings.gradle
I have: include ':ModuleA', 'moduleB'
but the directories at file system level are: moduleA/
and moduleB/
This seems weird and should not work but the first run always works, then the next ones will fail until project is cleaned.
I decided to keep things consistent and rename the directories as the settings.gradle
lists them, even when in AndroidStudio they appear with the name listed in settings.gradle
. This also helped to cleanup things because git has a configuration under .git/config
which states to ignore the case sensitive stuff.
So, check the case of your directories vs. how they are listed in settings.gradle
.
After renaming stuff and cleaning with gradle everything worked as before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With