Search code examples
javaandroidandroid-safe-args

Clashing class and package when using Android Safe Args


I'm struggling with a really annoying problem with Safe Args in Android (Java).

I have a project structure like this:

com.myapp/
├── activites/
│   ├── ActivityA.java
|   |   ├── FragmentA1
|   │   └── FragmentA2
│   └── ActivityB.java
├── view/
|   └── ...
└── model/
    └── ...

The important part here is the package com.myapp.activities.ActivityA.

When adding some navigation paths to the nav graph, Safe Args generates the structure as following:

com.myapp/
└── activites/
    ├── ActivityA/
    |   ├── FragmentA1Directions
    │   └── FragmentA2Directions
    └── ...

In this case I cannot compile my project because I get the error

error: class ActivityA clashes with package of same name.

This makes totally sense to me as the class com.myapp.activities.ActivityA gets generated to package com.myapp.activities.ActivityA but somehow I don't understand how I should avoid this problem. Is there something completely wrong my folder structure?


Solution

  • The usage of Fragments in an Activity seems really not to work.

    I put the Fragments into separate files to make it work like suggested by @ianhanniballake.