I was trying out Udacity course on developing android app.
above was the error i ran into when i tried creating an android test case while going through the lesson-4.
the problem is the test classes under the androidtest folderare packaged under com.sasharma.android.sunshine.testbut whenever i run the app in Androidtest configuration the gradle build the bUildCOnfig File for androidtest with the same package name and gives me the error "Error:(4, 1) error: package com.sasharma.android.sunshine.test clashes with class of same name"
Also i found that the only difference between the package names used by course instructors and the one used by me is that they are having an extra "app" to there package names like my package name for src\main\java*activity classes is also com.sasharma.android.sunshine but theirs is com.sasharma.android.sunshine .test and same goes for the package name under androidTest directory
Thanks in Advance!!!
Yes there is. You would need to implement your own Classloader and play some games to be able to access both during runtime.
Yes, it will work.
This answer is not useful. Show activity on this post. At runtime, the parameter types are replaced by Object . So saveAll(Collection<?>) and saveAll(Collection<MyClass>) are transformed to saveAll(Collection) . This is a name clash.
This is a late answer, but still, none of the answers provided the true reason for why this error is shown.
You get this error when one of your package names are the same as one of your classes, as shown below:
main
java
com.yourpackage.mycoolapp
somePackage
myclass.java
class2.java
somePackage.java
as you can see above the pack name somePackage
and the class name somePackage.java
, has the same name.
To fix this you can either change the package name or the name of the class:
Right click on package/class -> Refactor -> Rename
Done, no need to rebuild.
I think you have test.java file in your project files. Rename it to something else.
for android-studio click on test.java and Go to ReFactor-->Rename
Go-to Build-->Rebuild Project.
I fixed the same issue by changing applicationId in app\build.gradle
and rebuilt the project. My applicationId in build.gradle
was the same as package
name concatenated with appname
from AndroidManifest.xml
.
Before the change:
build.gradle
defaultConfig {
applicationId "com.mypackage.MyAppName"
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage" >
<application
android:name="MyAppName"
</application>
</manifest>
After the change:
defaultConfig {
applicationId "com.mypackage.MyApp"
}
I had this error in two places:
MyProjectName/app/build/genereted/source/buildConfig/androidTest/debug/mypackage/MyClass/test
MyProjectName/app/build/genereted/source/r/androidTest/debug/mypackage/MyClass/test
both contained package com.mypackage.MyClass.test;
what was reported had an error.
I try to rebuild the project and solve the problem.
Build->Rebuild Project!
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