How to structure AndroidManifest.xml with custom directory structure

Clash Royale CLAN TAG#URR8PPP
How to structure AndroidManifest.xml with custom directory structure
I have a directory structure like this:
build.gradle
module/
build.gradle
pack/
AndroidManifest.xml
src/
com/
example/
sub/
main/
index.java
foo/
index.java
bar/
index.java
I am not quite sure that is right in the first place (too many top-level folders it seems like). It seems like it should be more like this instead:
build.gradle
AndroidManifest.xml
com/
example/
sub/
main/
index.java
foo/
index.java
bar/
index.java
Ideally I would like to have it just be like this:
build.gradle
AndroidManifest.xml
src/
main/
index.java
foo/
index.java
bar/
index.java
Either way, the question is, how to write the AndroidManifest.xml so that it handles the main/index.java as the starting point. I have this currently:
main/index.java
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sub">
<application android:label="myproject">
<activity
android:name=".main"
android:label="myproject">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Wondering how I should change these three parts:
<application android:label="myproject">
<activity
android:name=".main"
android:label="myproject">
I would prefer not to create the xml resource files like in the res folder to keep strings.xml for the name and such. I would just like to hardcode the name into the AndroidManifest.xml if possible.
res
strings.xml
Also note, the main/index.java file contains a class such as MyActivity.
main/index.java
MyActivity
android:name=".main/index"
2 Answers
2
As far as I know, it is not possible. It is default project structure and you can not modify the AndroidManifest.xml file to have your custom directory structure for your Android project.
AndroidManifest.xml
<application android:label="myproject">
<activity
android:name=".main"
android:label="myproject">
Here android:label value is string resource. You can either modify them in res/values/strings.xml which is recommended or you can hardcode them and update them here only.
android:label
res/values/strings.xml
recommended
@Pollard thanks for accepting my answer. Please upvote as well if you find it worthy.
– VicJordan
Aug 8 at 11:18
As You want to access the index.java file which is located in the path
index.java
file
path
src/
com/
example/
sub/
main/
index.java
You need to change the package name like below:-
package
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sub.main">
<application android:label="myproject">
<activity
android:name=".index"
android:label="myproject">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Reference:-Why so many metadata files in Android studio?
This is not an answer to the question. Please read it again.
– VicJordan
Aug 8 at 4:33
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I would assume that main.java is an Activity so something like
android:name=".main/index"? Btw I don't think we should use the web like coding style in Android.– Enzokie
Aug 8 at 5:04