How do I remove libraries from the makefile in android studio? - android-studio

So I have a c++ game that I compile to an android app using the ndk. I use android studio with gradle to achieve this. I have an Android.mk file where I add all my includes and libraries (in the LOCAL_SHARED_LIBRARIES section) such as SDL2, SDL2_image, Box2D and so on. I tried out firebase analytics for a while, but ended up not using it. I had firebase_analytics in my android makefile just like the other libraries, and then removed it and its related things when I was done with it. However, when I build my project it gives me an error saying no rule to make target 'firebase_analytics'. Why is it still trying to build firebase? I removed it from the file. Maybe it cached something and it's building off of that? I tried cleaning the project and rebuilding it but it gives me the same error. Anyone know why this is happening (and what I can do to solve it)? Thanks for any help.

Related

Add library 'Gradle:' to classpath in Android Studio

The project is a generated LibGDX project. It used to work fine, but when I updated to Android Studio Chipmunk, the android module din't work fine anymore. So recently, I've updated to the Dolphin version which I thought could fix the problem. Well, it's still the same:
Error Image
As you can see, the external dependencies aren't detected and causing unresolved symbol errors. The library includes: the 'core' module, libgdx Android backend, and Play Service Ads (Admob).
I've tried rebuilding the project, updating everything that is possible, and tried solving it in the build.gradle file. However, it seems to be a problem in the IDE or me...
The project still builds and runs well, as if there's nothing wrong at all.
How can I fix this problem?

Building tess-two into a project using Android Studio's gradle build

There are answers about getting the tess-two project integrated into an Android project within Android Studio, but many are out-dated and none used the current capabilities defined here:
Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI)
What specific steps would be required to make tess-two functionality a part of the resulting APK, using functionality within Android Studio, rather than external file placement, manipulation and command line tools? So taking the building, creation of *.so files into the IDE. Specifically using just Android Studio's integrated build system (Gradle) as described here.
1. Start a new project
2. Import Tess-Two into the project
2b. Add any needed plug-ins
3. Add code in the main activity to get native functionality
4. Configure Android Studio build so that native functionality is available
This is where the specifics are required
4. Configure Android Studio build for native functionality
4a. Link C++ Project with Gradle
First, check the tess-two project for build files. You may select CMakeLists.txt or Android.mk files. Both are currently supported.
In this case, I used ndk-build, which seemed like a good bet for integrating the native code.
For more information, see Android Studio documentation
4b. Manage Long Commands
In Windows, errors may be encountered if the command length grows too large. To prevent problems, use LOCAL_SHORT_COMMANDS AND APP_SHORT_COMMANDS in the Android.mk file.
The "e=87" error is what you are avoiding by doing this:
For more on that topic, see stackoverflow question about error 87.
4c. Add Module Dependency for tess-two
In File > Project Structure > Dependencies use the + to add the tess-two dependency:
4d. Build the Project and check .apk file for .so files
The build, which takes a long time, should complete now. Validate that the .apk file contains the .so files, created during the build. With the tess-two libraries in an static initializer, run the project on your Android device:

Does Android Studio support Code completion for C/C++?

The code completion is fine on Android Studio java project. But I want to use Android Studio to edit some existing C file(.cpp).
for example, if i have declared some function, then i type the function in other section. But the android studio doesn't show up the code suggestion or some debugging.
Can Android Studio support Code completion for C/C++ like this:?
Yes it does, as long as the project is setup to use the NDK and the C/CPP sources are included in the project.
Try pulling the ndk sample repo and try opening one of the projects.
If you have a java project and want to edit some arbitrary C or C++ source, then no. It does not have enough information about the source file, include paths, compiler etc...
If your project uses Android.mk to build, it will be a bug of Android Studio. I have been reported.
Android.mk project cannot show code completion for cpp.
It seems that old version of Android Studio does not support code completion of jni native build (with Android.mk as configuration file), and that should already be fixed now.
But if you are using CMake in your project as external building tool and code completion still does not work, It's probably because you have more than one version of cmake installed. You can try to remove extra ones from SDK manager and restart Android Studio, it should work.
To see installed CMake version, you can open the SDK manager and check the 'show package details' on the right bottom. You can view cmake tools installed with different versions.

INSTALL_FAILED_DEXOPT zip archive does not include classes.dex

I've been struggling with this problem for 2 days. I can't debug my application on my android device using Android Studio.
This is the error I get:
[INSTALL_FAILED_DEXOPT]
When I look at the logs, it says "zip archive does not include classes.dex"
So the problem is that classes.dex isn't being built into the APK. This is true since the file size of my APK is now around 1MB whereas it used to be around 1.3MB.
I have tried everything, but I have no idea why classes.dex isn't being built into my APK. Any help is greatly appreciated.
Joaquin
Try cleaning your build, and build the app again.. Make sure you've added the activities to the Android manifest. Once you get the apk use 7zip to view apk and check if there is classes.dex or use native zip viewer if on Linux. And if nothing still works try synchronizing the build files so that gradle can detect non ide changes.
I just tried disabling my antivirus (Avast), cleaning and rebuilding the app and then restarting Android Studio.
Those steps worked and I can now debug my application on my android device again.
Note that classes.dex is only generated if your project contains Java classes. So if you are using the NDK in combination with native activities, there won't be no Java code at all and therefore no classes.dex. In that case, you have to set the hasCode attribute in the manifest to false because otherwise dexopt will be looking for it.
http://developer.android.com/guide/topics/manifest/application-element.html#code

Android Studio: disabling "External build" to display error output create duplicate class errors

I am starting my migration from Eclipse to Android Studio, and start playing with new projects on Studio.
My test project was working fine till I got some errors messages.
I had to do some manipulation (https://stackoverflow.com/a/16876993/327402) to enable the error output to display, and found the issue that I fixed.
Unfortunately, after this "workaround" (Why the hell have I to make such things to see my errors?), I found that there was an error message that I cannot fix:
error: duplicate class: com.mypackage.name.BuildConfig
error: duplicate class: com.mypackage.name.R
I also noticed that I am not the only one to have this issue (see the comment in the SO answer I linked above)
First time, I was able to fix it by enabling "External build" again, but that happened again, because I needed to see the error output and everything is now broken, and I cannot find what happen.
With Eclipse, the R file was easy to find, in the gen folder, but with Android Studio, there are too many files, and I am a little bit lost.
Any idea/suggestion?
I've found a question like this that has some replies here:
Cannot resolve R.java, duplicate class
You can try this:
Delete the Build folder generated by Android Studio automatically
Also you can try to Rebuild project by clicking Build->Rebuild project after deleting build folder.
So, just to let you know...
A few minutes after I posted my question, Google released an update to Android Studio (0.1.5)
See link: https://plus.google.com/+AndroidDevelopers/posts/Y9vhvGaHCbh
Tor Norbye kindly answered my question in this community, and I am sharing here
So the workaround I quoted in the OP is no more mandatory.
Enabling again External build after upgrading Android Sudio let me see the real errors ( a library and some Gradle import that I fixed)
So, I consider the Android Studio upgrade as the best answer to this question...
Ok, I also have the same problem, and this is what worked for me.
I first unticked external build from compiler settings. Then when I compiled i get two errors related to R.java, duplicate class.
Then i delete the build folder manually from finder. Then rebuild it from android studio, but still same error.
Then I again go back to compiler preference and tick the external build setting, and it worked fine after that.
Looks like some bug.
apparently, or at least for me 0.1.5 has a bug and cannot run in external build
because of some path error you can read about here
https://code.google.com/p/android/issues/detail?id=56628
so i switched to internal building, and then i hit the double R symbol bug
after deleting the build path application is compiled without errors but the build folder is not fully rebuilt, I'm missing the R.java file which the internal builder does not make.
i've rebuilt it on the external builder on an unupdated version as a temp workaround while this issues is fixed.
btw if anyone knows how to tell internal gradle to rebuild the build folder please share.
I just had the same problem and found a way to solve it (You can do this with Android Studio open):
Go to you Android Studio projects folder located in c:\users[USERNAME]\AndroidStudioProjects
Locate your project folder and open it.
Delete the folder named build.
From here, enter your application name folder, where you can find another build folder among with libs and src folders and a file named build.gradle.
RENAME the build folder to build2 or something else.
Now in Android Studio go to Build->Rebuild Project.
And after the project was rebuilt, open again the folder where the build2 folder that you renamed is located.
Delete the new folder named build that was created.
Rename your build2 folder to build again.
Done.

Resources