Migrate project to Gradle - android-studio

I've got a project that used to be in Eclipse. I've since moved it from there into Android Studio, though it's not using the Gradle build system yet.
I've setup my gradle files so that I can do gradlew build from the command-line and it will generate an APK for me.
My question now is how do I get Android studio to build using the gradle files that I've got setup instead of the using the "old" way?
For what it's worth, I'm on Windows 7.

Not sure how you are compiling the project with Android Studio without actually using Gradle because AFAIK Android Studio always uses Gradle under the hoods to build sources.
Anyway, if you have your Gradle config file ready you only have to import it to a new project in Android Studio (File > Import Project... and then select the build.gradle or settings.gradle)

Related

How to setup custom settings.gradle at Android Studio?

I need to build a project in Android Studio using second settings gradle file (for sample settings-lite.gradle). How to do that? Andriod Studio version is 2021.2.1.
PS: I don't need to build the project by CLI.

Can't find "Sync project with Gradle files" in Android Studio running on Mac

I'm running into the error when I tried to run the existing project.
Error: "AndroidManifest.xml doesn't exist or has incorrect root tag"
I'm seeing a lot of solutions suggesting using "Sync project with Gradle files". I'm running Android Studio on my Mac and did not see that option. I do have AndroidManifest.xml file in the project but for some reason Android Studio can't find it.
I have the file under project_name > app > src > main > res.
I have Android Studio 4.1.1 and macOS Catalina 10.15.7
I also got a recommendation when I open up the Android Studio
Migrate Project to Gradle?
This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
More Information about migrating to Gradle
Don't show this message again.
Not sure what to do about it. I'm pretty new to Android Studio. Thanks!

Open cocos2d-x-3.7 in Android Studio

What is the proper way to open cocos2d-x-3.7 in Android Studio?
I tried:
Open existing project in Android Studio project > Choose proj.android-studio directory (In another attempt, I also tried to choose the base directory MyGame)
Run
Error: couldn't find "libcocos2dcpp.so.
Moreover, it also does Classes directory in the Project.
Android Studio is only partially supported in cocos2d-x 3.7 and 3.8. With the default project you will only be able to run your app without debugging using Android Studio.
Prior to running your app in Android Studio you will have to compile using the Android Studio flag:
cocos compile -p android --android-studio
You will have to run this command after any changes to your app are made, since the default Android Studio currently doesn't compile your project.
Furthermore the default Android Studio project does not include the Classes directory.
Suggestion: Use Eclipse or Xcode to develop your cocos2d-x projects for now. Hopefully future versions of cocos2d-x will have better support for Android Studio out of the box, this is critical considering Google is dropping support for Eclipse.
When you try to run the application on Android Studio, you get the error couldn't find "libcocos2dcpp.so" because it doesn't have the NDK for building your game.
I recommend you to compile proj.android and import that, cocos2d-x 3.7 doesn't support full Android Studio yet. Do this:
cocos compile -p android
Then import your proj.android to Android Studio.
Now you can run your application but you won't able to debug it, bad news (it will just install the APK on your device or virtual device).
Hope it helps.
Error: couldn't find "libcocos2dcpp.so.
For this you need to compile android studio project first so .so files and classes folder will be generated.
Open your command line and enter the following command to compile your android studio project:
cocos compile -p android --android-studio --ap android-24 --app-abi x86
This will create required files in your proj.android-studio directory.
Now import this project into Android Studio and try to run it.

How to import a android project into android studio?

I want to study the source code of android-smspopup .But when I download the source code and import this into android studio, the android studio pop up a dialog with a title"Import Gradle Project" and a blank to fill named Gradle home. Does any one know why this happens? And what to fill in Gradle home?
The source code doesn't include the Gradle wrapper files, which it should; the Gradle wrapper is responsible for automatically downloading the correct version of Gradle so you don't have to go through this trouble. I would recommend that you copy the Gradle wrapper over from another project into this source tree and use it. In another project that you've created with the New Project wizard, copy these files to the root directory of the project:
gradlew
gradlew.bat
gradle (directory)
When you open up the project in Android Studio it's likely to complain about the version of the Android Gradle plugin and offer to fix it for you; let it do that. If you're running the latest version of Android Studio (0.4.6 as of this writing), it's fairly smart about getting the versions of Gradle and the plug-in right, but in older versions it could get a little confused and have to ask you multiple times.
NOTE: instead of copying the wrapper files over, you can instead install a compatible version of Gradle and put the installation directory in when it asks for Gradle home. That will work, but be aware that Android Studio is very finicky about what version of Gradle it's compatible with; usually it requires a specific version that isn't forward-compatible, so for example, if it wants 1.10, 1.11 won't work. As you upgrade Android Studio you'll have to upgrade Gradle as well and it will be a bit of a drag; if you use the wrapper it's easier to make that change.
By the time Android Studio hits 1.0, it will sort out the version issues with Gradle, and it won't be so picky about version numbers, but in the short term, it's a limitation.

Android Studio project can't resolve ActionBarSherlock imports

I have an Android Studio project which has a dependency on ActionBarSherlock set in build.gradle:
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile project(':Core')
compile fileTree(dir: 'libs', include: '*.jar')
}
The project builds successfully on the command line with gradle assemble assembleDebug and also builds and runs just fine from the IDE when I press ctrl+D. When I view some of the Sherlock-related source files in the IDE, though, the file is full of red error notifications, starting with this line:
import com.actionbarsherlock.app.SherlockPreferenceActivity;
The tooltip that pops up says
Cannot resolve symbol 'SherlockPreferenceActivity'
and none of the context-sensitive stuff such as auto-completion is available.
I had tried the File > Invalidate Caches/Restart > Invalidate and Restart menu option, which doesn't seem to have cured the problem. How can I get Android Studio to correctly resolve this import?
First sync your project with gradle and check if it gives some error, if it worked fine go back and try importing something from actionbarsherlock library in any of your class.
If above step doesn't help. Check once Your_Project/your_module/build/exploded-bundles/ComActionbarsherlock.../classes.jar exists or not.
Then go for this :
Clean your project from Build > Clean Project, sync your project with gradle than check this for reference.
Import Google Play Services library in Android Studio
Or Follow the steps :
Exit Android Studio
Delete all the .iml files and files inside .idea folder from your project
Relaunch Android Studio and wait till the project synced completely with gradle
This is bug in Android Studio 0.4.2 and fixed for Android Studio 0.4.3 release.

Resources