Android App

Copy and rename an Android project in Android Studio

by Little Bear @August,03 2018 17.00 ( IP : 171...77 ) | Tags : Android App

วิธีสำเนา Android Application Source Code ไปเป็น Application ใหม่ ลองทำตามขั้นตอนดังนี้

Copy and rename a project

For some lessons, you will need to make a copy of a project before making new changes. You may also want to copy a project to use some of its code in a new project. In either case you can copy the existing project (ExistingProject), and then rename and refactor the new project's (NewProject) components to use the new project's name. (In the instructions below, substitute your actual project names for ExistingProject and NewProject.

1. Copy the project

  1. On your computer's file system (not in Android Studio), make a copy of the ExistingProject directory.
  2. Rename the copied directory to NewProject .

2. Rename and refactor the project components

The old name of the project, ExistingProject, still appears throughout the packages and files in the new copy of your project. Change the file and the package references in your app to the new name, as follows:

  1. Start Android Studio
  2. Click Open an existing Android Studio project.
  3. Navigate to the NewProject directory, select it, and click OK.
  4. Select Build > Clean Project to remove the auto-generated files.
  5. Click the 1:Project side-tab and choose Android from the drop-down menu to see your files in the Project view.
  6. Expand app > java.
  7. Right-click com.example.android.existingproject and choose Refactor > Rename. This opens the Rename dialog.
  8. Change existingproject to newproject.
  9. Check Search in comments and strings and Search for text occurrences and click Refactor.
  10. The Find Refactoring Preview pane appears, showing the code to be refactored.
  11. Click Do Refactor. (ปุ่ม Do Refactor อยู่ที่แถบด้านล่าง มองหาตั้งนาน เพิ่งเจอ)
  12. Expand res > values and double-click the strings.xml file.
  13. Change the name="app_name" string to New Project.

3. Update the build.gradle and AndroidManifest.xml files

Each app you create must have a unique application ID, as defined in the app's build.gradle file. Even though the above steps should have changed the build.gradle file, you should check it to make sure, and also sync the project with the gradle file:

  1. Expand Gradle Scripts and double-click build.gradle (Module: app).
  2. Under defaultConfig, check to make sure that the value of the applicationID key has been changed to "com.example.android.newproject". If it has not changed, change it manuall now.
  3. Click Sync Now in the top right corner of the Android Studio window.
    Tip: You can also choose Tools > Android > Sync Project with Gradle File to sync your gradle files.

In addition, some apps include the app name in readable form (such as "New Project" rather than newproject) as a label in the AndroidManifest.xml file.

  1. Expand app > manifests and double-click AndroidManifest.xml.
  2. Find the statement below, and if necessary, change the label if to the string resource for the new app name:

android:label="@string/app_name"



อ่านรายละเอียดต่อได้ที่ Copy and rename a project



แสดงความคิดเห็น

« 7206
หากท่านไม่ได้เป็นสมาชิก ท่านจำเป็นต้องป้อนตัวอักษรของ Anti-spam word ในช่องข้างบนให้ถูกต้อง
The content of this field is kept private and will not be shown publicly. This mail use for contact via email when someone want to contact you.
Bold Italic Underline Left Center Right Ordered List Bulleted List Horizontal Rule Page break Hyperlink Text Color :) Quote
คำแนะนำ เว็บไซท์นี้สามารถเขียนข้อความในรูปแบบ มาร์คดาวน์ - Markdown Syntax:
  • วิธีการขึ้นบรรทัดใหม่โดยไม่เว้นช่องว่างระหว่างบรรทัด ให้เคาะเว้นวรรค (Space bar) ที่ท้ายบรรทัดจำนวนหนึ่งครั้ง
  • วิธีการขึ้นย่อหน้าใหม่ซึ่งจะมีการเว้นช่องว่างห่างจากบรรทัดด้านบนเล็กน้อย ให้เคาะ Enter จำนวน 2 ครั้ง