Copy existing project with a new name in Android Studio

后端 未结 19 2184
野趣味
野趣味 2020-11-29 17:31

I would like to copy my Android project and create a new project from the same files just with a different name. The purpose of this is so I can have a second version of my

相关标签:
19条回答
  • 2020-11-29 17:42

    If you use Gradle - don't forget to change applicationId attribute in app/build.gradle file.

    0 讨论(0)
  • 2020-11-29 17:42

    As free3dom pointed out, here's what should be done:

    1. Create a copy using file manager
    2. Manually edit the app's build.gradle file to change the package name (you can use the file manager).
    3. Manually edit AndroidManifest.xml to change the package name.
    4. Run gradle sync.
    5. Open the project in Android Studio, and refactor the package name.
    6. Run gradle sync, again.

    That seems to work without any problems.

    0 讨论(0)
  • 2020-11-29 17:45

    I've tried from nt.bas answer and gnyrfta answer which works well for me.

    Quoting from nt.bas answer:

    If you are using the newest version of Android Studio, you can let it assist you in this.

    Note: I have tested this in Android Studio 3.0 only.

    The procedure is as follows:

    1. In the project view (this comes along with captures and structure on the left side of screen), select Project instead of Android.
      The name of your project will be the top of the tree (alongside external libraries).
      Select your project then go to Refactor -> Copy....
      Android Studio will ask you the new name and where you want to copy the project. Provide the same.

    2. After the copying is done, open your new project in Android Studio.
      Packages will still be under the old project name.
      That is the Java classes packages, application ID and everything else that was generated using the old package name.
      We need to change that.
      In the project view, select Android.
      Open the java sub-directory and select the main package.
      Then right click on it and go to Refactor then Rename.
      Android Studio will give you a warning saying that multiple directories correspond to the package you are about to refactor.
      Click on Rename package and not Rename directory.
      After this step, your project is now completely under the new name.

    3. Open up the res/values/strings.xml file, and change the name of the project.
    4. A last step is to clean and rebuild the project otherwise when trying to run your project Android Studio will tell you it can't install the APK (if you ran the previous project).
      So Build -> Clean project then Build -> Rebuild project.

    Up to this point you only rename your whole project name. To rename packaging name you need to follow gnyrfta answer which was described as:

    When refactoring the package name in Android Studio, you may need to click the little cogwheel up to the right by the package/android/project/etc - navigator and uncheck 'compact empty middle packages' in order to see each part of the package name as an own directory. Then for individual directories do refactor.


    PS: If you're having an

    Failed to finalize session : INSTALL_FAILED_INVALID_APK: Split lib_slice_0_apk was defined multiple times

    Just delete build folder of appmodule and Rebuild the project!

    This will fix the issue!

    0 讨论(0)
  • 2020-11-29 17:46

    If you are using the newest version of Android Studio, you can let it assist you in this.

    Note: I have tested this in Android Studio 3.0 only.

    The procedure is as follows:

    1. In the project view (this comes along with captures and structure on the left side of screen), select Project instead of Android.
      The name of your project will be the top of the tree (alongside external libraries).
      Select your project then go to Refactor -> Copy....
      Android Studio will ask you the new name and where you want to copy the project. Provide the same.

    2. After the copying is done, open your new project in Android Studio.
      Packages will still be under the old project name.
      That is the Java classes packages, application ID and everything else that was generated using the old package name.
      We need to change that.
      In the project view, select Android.
      Open the java sub-directory and select the main package.
      Then right click on it and go to Refactor then Rename.
      Android Studio will give you a warning saying that multiple directories correspond to the package you are about to refactor.
      Click on Rename package and not Rename directory.
      After this step, your project is now completely under the new name.

    3. Open up the res/values/strings.xml file, and change the name of the project.
    4. Don't forget to change your application ID in the "Gradle Build Module: app".
    5. A last step is to clean and rebuild the project otherwise when trying to run your project Android Studio will tell you it can't install the APK (if you ran the previous project).
      So Build -> Clean project then Build -> Rebuild project.
      Now you can run your new cloned project.
    0 讨论(0)
  • 2020-11-29 17:48

    The purpose of this is so I can have a second version of my app which is ad supported in the app store.

    Currently the best way to do it is without copying the project.
    You can do it using diffent flavors in your build.gradle file.

     productFlavors {
            flavor1 {
                applicationId = "com.example.my.pkg.flavor1"
            }
            flavorAdSUpport {
                applicationId = "com.example.my.pkg.flavor2"
            }
      }
    

    In this way you have only a copy of the files and you can handle the difference easily.

    0 讨论(0)
  • 2020-11-29 17:48

    The appendix of the Android Developer Fundamentals Course Practicals gitbook includes steps to copy and rename an existing project:

    https://google-developer-training.gitbooks.io/android-developer-fundamentals-course-practicals/content/en/appendix_utilities.html#copy_project

    0 讨论(0)
提交回复
热议问题