1. Are you ready for the Galaxy S20? Here is everything we know so far!

Copying existing project (source files) into another project

Discussion in 'Android Development' started by RATNAJEE, Jan 16, 2019.

  1. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    I'm having two projects A and B. I would like to import the classes and XML layout files from B to A. I surfed through the net and some made a suggestion to make the project as a Library module and implement it into the other project, I tried but the classes were not updated the newly created module. Can it be possible to import entire project into another project in android studio? If possible, instruct the procedure..
     


  2. Alexandr0617

    Alexandr0617 Newbie

    Hello! Yes, you can make a library from your project. For this put project B to root project A. Then add to settings.gradle the text
    include ':app', ':projectB'

    and add to build.gradle
    dependencies {
    ....
    implementation project(':projectB')
    ...}
     

    Attached Files:

    • exm.png
      exm.png
      File size:
      3.3 KB
      Views:
      71
  3. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    Alexandr0617: Thanks for your reply. I did that process, but the package name in project B was not recognised while importing. Can you suggest how to use the classes in project B in A?
     
  4. Alexandr0617

    Alexandr0617 Newbie

    Hm... This is strange. Can you give me the source code with an example of such an error?
     
  5. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    Sorry Alexandr0617, these are government projects. We are not supposed to give, but i can elaborate you the problem.
     
  6. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    I copied the project B in root directory of A. I included in settings.gradle file and Implemented project in dependencies. My requirement is to run the project B when the button in the class of project A was pressed. I called the 'start Activity' method to run the main activity class of project B. This giving error that the class was not recognised. If I did any mistake or if you have any alternative process, pls suggest me.
     
  7. Deleted User

    Deleted User Guest

    Have you tried this -

    Import as a module:
    1. Start Android Studio and open the project you'd like to add the module to.
    2. From the Android Studio menu click File > New > Import Module.
    3. Select the Eclipse ADT project folder with the AndroidManifest.xml file and click Ok.
    4. Modify the module name if desired, and click Next.
     
  8. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    Yes LV426, Thanks for your response. I tried this method but the classes were not imported and I tried to copy the classes from the project to the module then getting error: 'Unable to resolve dependencies '..even I implemented the module as dependency and I also added the dependencies from the project into this.
     
  9. Alexandr0617

    Alexandr0617 Newbie

    Yes, I understand what that problem is. I tried to make a new project with "subproject" and I have the same problem. See my solution
     

    Attached Files:

  10. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    Alexandr0617 thanks, can I copy the java files and res folder directly into the sub project? If copied, How to use those classes in project A?
     
  11. Alexandr0617

    Alexandr0617 Newbie

    Yes, you can. An example of using classes from project B you can see in ProjectA\app\src\main\java\com\template\projecta\MainActivity.java
    ....
    import com.template2.projectb.ToastUtils;
    ....
    ToastUtils.showMessage(getApplicationContext(), "Hello!");
     
  12. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    After implementing project in build.gradle, I'm getting this error.
     
  13. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    Unable to resolve dependency for ': app@debug/complieClasspath': could not resolve project : project B.
     
  14. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    Alexandr0617, I did the same that what you made in the project. It was compiled and APK was generated. But while opening the project B through APK, the app crashing.. What I have to do?
     
  15. Alexandr0617

    Alexandr0617 Newbie

    Can you send the crash message?
     
  16. RATNAJEE

    RATNAJEE Newbie
    Thread Starter

    Alexandr0617, now I'm facing a new error.
    After installing and running APK file, the main activity was executed but the further activities were stopped. In logcat, i found the error (attached), ' The activity already has an action bar supplied by the window decor. Do not request window.FEATURE_SUPPORT_ACTION_BAR and set windowactionbar to false in your theme to use a toolbar instead.' But my project need the toolbar. Can anyone help me to solve this problem?
     

    Attached Files:

Loading...

Share This Page

Loading...