Lesson 1: A couple of things to take care when creating a project
Once Android Studio is installed, most people create a new project in a snap. It's easy. However there are three things to keep in mind in the process, especially if this is one of your first Android projects.
First of all, you will be asked to pick the main activity for the project. Just FYI, "activity" is almost always a Google Android architects' code name for a screen. You look at your phone, you see a screen with an application, that screen is "activity". If this is one of your first projects, always pick "No Activity":

Why? Because any starting activity is a screen, and all other options you have are essentially templates, an empty activity prefilled with things, you can add later. With time you will learn more about those templates and will be able to pick the right one, but in the beginning you are just betting that you won't have to remove the stuff that the template will put in.
And remember, things in Android applications are always interconnected, so properly removing something there is usually much harder than adding.
Then you see a final screen, which most people don't pay much attention to and just press "Finish". If you did so, you will quickly start wondering:
Where are my source files?
My project belongs to namespace com.example.*, how can I change it to com.my_domain.*?
This is what the second and last screen creating the projects is for:
The sources by default should be in your home directory in a folder called AndroidStudioProjects, the home folder on Windows and Mac are in /Users/YourAlias/ and on Linux in /home/your_alias/.
The namespace may be changed in already existing project in one of the build.gradle (module) file in android.namespace and android.defaultConfig.applicationId:
android {
namespace 'net.galiel.simple1'
...
defaultConfig {
applicationId "net.galiel.simple1"
...
}
...
}
Then you'll have to change the namespace in all Java or Kotlin source files and move them to the correct folder, e.g. to …/net/galiel/ from …/com/example/.
However, it's much easier to set it right from the beginning. Don't try to find these setting in generic AndroidStudio configuration files, they are not there. Namespace is defined as described above, and the location of source files are not in the config files at all. It is defined by where the files actually are.
That's it for the beginning. C U next time!

Comments
Post a Comment