I'm porting from eclipse to android studio, do I need to import appcompat_v7 from my existing eclipse project into android studio?
As stated in Android's Support Library Overview, it is considered good practice to include the support library by default because of the large diversity of devices and the fragmentation that exists between the different versions of Android (and thus, of the provided APIs).
This is the reason why Android code templates tools included in Android Studio through the Android Development Tools (ADT) integrate them by default.
An example would be the ability of using the Fragment API which appears on API 11 (Android 3.0 Honeycomb) on a device that runs an older version of this system. Or the newer RecyclerView which was introduced in API 21 (Android 5.0 Lollipop) can be used on pre-lollipop devices with the user of appcompact.
It is also to be noted that you can deactivate automatic inclusion of the Support Library by default.
To import a project to Android Studio:
Start Android Studio and close any open Android Studio projects.
From the Android Studio menu select File > New > Import Project.
Select the Eclipse ADT project folder with the AndroidManifest.xml file and click Ok.
Select the destination folder and click Next.
Select the import options and click Finish.
The import process prompts to migrate any library and project dependencies to Android Studio, and add the dependency declarations to the build.gradle file. The import process also replaces any well-known source libraries, binary libraries, and JAR files that have known Maven coordinates with Maven dependencies, so you no longer need to maintain these dependencies manually. The import options also allow you to enter your workspace directory and any actual path maps to handle any unresolved relative paths, path variables, and linked resource references.
Android Studio imports the app and displays the project import summary. Review the summary for details about the project restructuring and the import process.
After importing the project from Eclipse ADT to the new Android Studio project and module structure, each app module folder in Android Studio contains the complete source set for that module, including the src/main and src/androidTest directories, resources, build file, and Android manifest. Before starting app development, you should resolve any issues shown in the project import summary to make sure the project re-structuring and import process completed properly.
The process is changed frequently so the text above will probably be outdated very soon whilst the link below will be updated so the link is you're best bet. The link also provides pictures to help aid the process.
https://developer.android.com/sdk/installing/migrate.html
You should be written your build.gradle file.
This is script.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1' //Support Library
}
Related
I am having problems setting up my eclipse program with Android for my first project. After installing eclipse together with the android developer tools, I tried to create a new 'Android Project' with a minimum sdk of Android 2.2, a target sdk of Android 6.0 and a sdk compiler of Android 7.1.1.
After clicking run, Eclipse displayed an error, which indicated that there was issues with my empty activity:
Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'
I have done my research for this problem and most of the solutions suggested importing an Android Project called "AppCompat-v7". However, upon selecting the file, there were no projects found that could be imported. This is what I see:
Import project window:
I have spent numerous hours trying to fix this issue. I have ensured that both my eclipse program and all android files are under the same hard disk, I have tried adding the file to the build path etc. but the same problem persists.
Anyone out there who can help me with this issue please? I would greatly appreciate it :) If you need more details regarding what I have done so far, feel free to contact me!
Someone commented below suggesting that I import the "AppCompat-v7" folder to the package explorer and then go to Project->Properties to add the appcompat library folder. I managed to add the folder to my package explorer but I am not able to add the library to the project, as no library options show up. This is even so after checking the "IsLibrary" box.
AppCompat-v7 should be added to your module Gradle file.
It goes in the dependencies section.
For example:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.1'
testCompile 'junit:junit:4.12'
}
if you have Appcompat v7 in your extras folder follow this link but if you don't have it:
To download the Support Library through the SDK Manager:
Start the Android SDK Manager.
In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.
Select the Android Support
Repository item. Click the Install packages... button.
After downloading, the tool installs the Support Library files to your existing Android SDK directory. The library files are located in the following subdirectory of your SDK: <sdk>/extras/android/m2repository/com/android/support/ directory.
Update: Import it like this picture
you are now have your library in your project Explorer like this
the rest is adding library project
Novice question.
What is the recommended way to run the sample apps, included in the Facebook SDK, in Android Studio (0.8.6)?
The ideal answer would include step-by-step instructions.
I'm using Android Studio version 0.8.0, and Facebook SDK 3.18.
When I tried to open a sample as a separate project, it can't find Gradle and wasn't able to run it. However, when I imported /samples folder as a root, all sample projects were imported and was able to run each samples.
File > Import Project > Select FACEBOOK_SDK_PATH/samples > OK > Create project from existing sources
and then, click next/ok as Android Studio's default setting.
Hope it helps!
Suposing you already downloaded and unzipped the SDK.
Create your android project. Gradle based.
File -> Import Module. Navigate to the unzipped folder and select the unzipped folder.
Add the library dependency in your main module (the one created with your project) adding this line in your build.gradle:
Synchonize project.
If you want to continue creating your own app, you might add the dependency module build.gradle file:
android {
dependencies {
compile project (':facebook')
}
}
We currently use Eclipse for Android development , and our projects are synchronized to an SVN .
Current structure :
Android Application 1
Android Application 2
Android library 1
Android library 2
It is therefore independent projects on SVN.
Details :
Android Android app 1 need library 1
Android Android app 2 need library 1 and 2 , etc ...
Until then, it is quite normal.
The challenge is to move to the project structure in Android Studio / IntelliJ , while ensuring compatibility with eclipse . So changing NOTHING in the current structure of SVN .
And I just can't handle how to do this with the IntelliJ structure (projects, modules, ... ) .
In addition there appears to have a problem with Android Studio, it is impossible for me to IMPORT module , I can create one, but not import one...
And that's not all , in "Open Module settings" , only Android SDK Appears for EACH project. So I can not handle modules ...
I tried to import each project one by one with a checkout from Subversion, it works, but how to link projects to each other then ? I end up with a project structure as in eclipse, and I guess that is not good.
In Android Studio, a module is dependent on a project (right ?), but I do not want a library dependent of any project.
Please, do not hesitate to ask any information. I'm sure that I didn't say everything, because I try that from 2 days now, so I've try many many things... I just can't get it.
What's wrong ?
Thanks a lot
Best Regards
Firstly you should generate a gradle build file for each of your projects. You can do this in Eclipse. Go to File > Export > Android Gradle Files.
At the end you should have this architecture on you project :
root
build.gradle
settings.gradle
AndroidProj1
build.gralde
AndroidProj2
build.gradle
AndroidLib1
build.gralde
AndroidLib2
build.gradle
Make sure that all your projects are refereced in your settings.gradle. You should have these lines:
:AndroidProj1
:AndroidProj2
:AndroidLib1
:AndoridLib2
Then, in build.gradle files of your projects, you can make references of other projects. If AndroidProj1 depends on AndroidLib1, then you should have these lines in build.gradle of AndroidProj1:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':AndroidLib1')
}
When Eclipse generate gradle files, it keeps the old directory structure so you can keep using Eclipse.
In Android Studio, you should import only the root project. It will find the underlying projects.
Then you can try to build your projects.
For each project within Eclipse, you should go to File > Export > Android Gradle Files and then use these files to import into Android Studio.
However, I think once imported into Android Studio, it is then not compatible with Eclipse. I have had many issues trying to reference libraries for my apps in Android Studio and I eventually gave up. Android Studio is still in a very early release and therefore there are still lots of bugs and issues within Android Studio. Therefore, I wouldn't recommend moving to Android studio as yet and stick to Eclipse for the time being until a stable version is released.
I have a setup of android project on eclipse and I want to migrate to Android Studio. So, I have android-support-v4.jar that I use for my main project and my Facebook lib-project.
I guess I have to exclude lib-projects as a folder in my main module (lets call the main module Jack). Jack has dependancy on the facebook lib-project.
How should I define the android-support-v4.jar as a separate library and use it in both projects? Or should I just use directly the jar files and leave them in both Jack's libs folder and Facebook libs folder?
If the first option should be done, will ant clean release still work (with the build.xml android generated file)?
In Android Studio, builds are done with Gradle now. Gradle is different. With gradle, you tell your project which jar's you need, and it will connect to a server and download them if it doesn't already have them when you compile your apk.
A few things to note:
When you install Android Studio, it has it's own Android sdk directory. You have to download everything from the sdk downloader (from inside the Android Studio App) again. Don't bother trying to switch the sdk download path to your current one. You will only encounter bugs (Or at least I did).
So your question is worded very confusingly. It sounds like you have a main module, and then you have a library module, and the library module uses the support library.
You'll need to set it up so the main module has a dependency on your library module. From there, you'll need to go into your library module's gradle file and tell it that you want to include the android support library
dependencies {
compile 'com.android.support:appcompat-v7:19.0.0'
}
The support library is a little weird in gradle. Gradle normally would download the dependencies you need. However, android studio requires that you have the support library installed through their sdk downloader (top-right group of icons in android studio. The download icon).
After you get all your dependencies entered into your gradle file, you'll then need to go to Tools -> Android -> Sync gradle files with project. From there compile errors should go away, and you should be able to run the project.
Best of luck. By the way, Here is the documentation on Gradle on the android website. I find myself having to go to it A LOT, especially when I made the switch from Eclipse to Android Studio. This + Various tutorials I found as needed via google. http://tools.android.com/tech-docs/new-build-system/user-guide
EDIT: This link might also be helpful. Google has some steps for switching from eclipse to Android Studio: http://developer.android.com/sdk/installing/migrate.html That with some of the stuff above may prove helpful.
While I haven't tried this myself, I suggest you use the recommended migration steps provided by Google in this article.
Before you do that, though, make sure that you either:
Check that both support libraries on the main project and dependencies have the same version (Eclipse will complain about it during build time, and will likely cause problems during conversion to Gradle script.); OR,
Uncheck the "Android Private Libraries" entry on the Order and Export tab of the dependency project's build settings.
If the migration process described doesn't work smoothly for you, you can always call the Ant build script from within the Gradle script, as described here.
The Android Studio uses only Gradle, but you can export Android ant project from eclipse.
To do that go to File -> import project usually next, next, next... works.
If not go to project setting Shift + Ctrl + Alt + S and under modules -> PROJECT_NAME -> Dependencies you can add your support library.
To add a Facebook library you must add it as another module to your project.
If you still want to use Ant there is another option: Use Intellij IDEA which support Ant.
im'triyng to implement the Google Licensing Verification in a Android Studio made app.
By following this lines: http://developer.android.com/google/play/licensing/setting-up.html seems tath:
As an alternative to adding the LVL as a library project, you can copy the library sources directly into your application. To do so, copy (or import) the LVL's library/src/com directory into your application's src/ directory.
I've done this but the import of:
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
fail..
Searching on google i've been noticed that i need to modify the build.grade file on my project, but i can't find a specific solution.
How can I reference the LVL in my android studio project?
There is some tutorial or example?
Thanks
Lorenzo
In Android Studio, Tools-Android-SDK Manager
In SDK Manager, in the extras section choose Google Play Licensing Library
Go back to Android Studio, and choose File-New-Import Module
ADK Manager will have put the downloaded files under your SDK directory, in my case Desktop/android-sdk-macosx/extras/google/play_licensing/library
Choose to import this directory as a module, and give it a name. I used 'lvl'
Optionally change targetSdkVersion in the lvl module's build.gradle to match your project targetSdkVersion.
Then in your projects build.gradle, add the line compile project(':lvl') inside the {dependencies{ section.
Re-sync Gradle and everything should compile correctly.
Finally I've got the solution!
You have to put the library/src/com directories in the youroject/scr/main/java/com and then click on the "Sync project with Gradle files" button.
step 6 is placed in
inside the project(":android"){dependencies { section.
Copying the LVL sources to your application.
As an alternative to adding the LVL as a library project, you can copy the library sources directly into your application. To do so, copy (or import) the LVL's library/src/com directory into your application's src/ directory.
Visit:http://developer.android.com/google/play/licensing/setting-up.html