My project uses these plugins:
OneSignal
GooglePlayServices
Adjust
Google Analytics
Unity IAP
Facebook SDK
Those plugins are used in almost every project.
But I am over field references count
This is my .aar file list
What should I do to decrease reference count?
So What should i do to decrease reference count ?
You have so many plugins with many functions/fields. There is a limit when building this from Unity's Editor and you have reached that limit.
To decrease reference count, you have to delete some these plugins but I am sure that you need them and deletion may not be the appropriate solution in this case.
The only way to actually get around this and build for Android at this moment is to export the Project as Android Project then build it with Android Studio. This removes the reference limit imposed by Unity's Editor.
EDIT
I forgot to mention that you have to enable multidex after exporting it out. Since many people go through this problem daily, I decided to add a thorough instruction on how to fix this problem by exporting it out and also how to fix it without exporting it.
FIX BY EXPORTING THE PROJECT
1A.Export the Unity Project as Android Project.
1B.Import into Android Studio:
If you get grade error when importing into Android Studio like the one below:
Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection
cannot be cast to
org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
In the "dependencies" block which is in the "buildscript" block in the build.gradle file, change:
classpath 'com.android.tools.build.gradle.2.1.0'
to
classpath 'com.android.tools.build:gradle:2.2.3'
If you export the Project and still get the-same error, you need to manually enable multidex. Below is a simplified step to follow from Google's doc that will be shown to you in the error:
2.Add android:name="android.support.multidex.MultiDexApplication" > to the
application tag in the AndroidManifest.xml file.
3.Add compile 'com.android.support:multidex:1.0.1' to the "dependencies" block in the build.gradle file.
4.Add multiDexEnabled true to the "defaultConfig" block which is in the "android" block in the build.gradle file.
Build APK and see if it works. If the reference count error is gone, stop here.
5.Getting a GC overhead exception like the one below?
java.lang.OutOfMemoryError: GC overhead limit exceeded
Increase the heap size that will be used when performing dex operation. From this solution, add the following to the "android" block in the build.gradle file:
dexOptions {
javaMaxHeapSize "4g"
}
FIX WITHOUT EXPORTING THE PROJECT
Must have Unity 5.5 and above to do this:
1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates, Copy the mainTemplate.gradle file to your <ProjectName>Assets\Plugins\Android folder.
2.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk, Copy the AndroidManifest.xml file to your <ProjectName>Assets\Plugins\Android
3.Open both the mainTemplate.gradle and AndroidManifest.xml file you just copied with Visual Studio then do the modification from the FIX BY EXPORTING THE PROJECT instruction above. Skip/Ignore step #1A and #1B. Just do steps from #2 to #5. That's it.
This is what the final mainTemplate.gradle should look like and this is what the final AndroidManifest.xml should look like. This is only for reference purposes. I suggest you don't use mine but instead follow the copy steps above to create yours because future Unity versions can come with different files. You want to make sure you use the latest one or you may have problems building it.
4.Build APK and see if it works:
--
If the reference count error is gone, stop here:
5.Getting an error like the one below?
Build Failure Release builds have to be signed when using Gradle
Just sign the apk from the Publishing Settings in the Build Settings. You can create new keystore or use an existing one.
6.Another error like below?
Error: Avoid hardcoding the debug mode; leaving it out allows debug
and release builds to automatically assign one [HardcodedDebugMode]
Remove android:debuggable="true"> from the AndroidManifest.xml file.
If this non exporting solution did not work for you then you have to
use the exporting solution.
IMO, The accepted answer isn't correct (or only partly correct). Exporting an Android studio will not "magically" fix this issue. Also, from my experience, the exported Android studio project does not always build right away and you have to fix lots of things before you can actually build it.
You are using lots of plugins and so you faced an Android limitation of not being able to reference more than 64k methods.
There are a few things you can try to solve this:
Delete some of these plugins, if possible (as already suggested in the accepted answer).
Use multidex. In the past this was only possible by exporting the project to Android studio and building it there. Starting with Unity 5.5 you can build your project using Gradle right from Unity. This means you can create a custom gradle file that configures your game to use Multidex. This doesn't reduce the method ref count, but it works around it by splitting your native Java count into multiple dex files.
Use ProGuard - since you can use Gradle from Unity, you can also define ProGuard to run and remove any code that is not used.
Related
Update: While a root cause has not been determined for these errors. I have been able to fix my issues via reimporting and reinstalling the Google AdMob Manual SDK all together.
New to this whole Stackoverflow, not sure if I should make that as the answer?
I'm attempting to install the Google AdMob module into my SwiftUI iOS application using the Manual SDK method located on their documentation page. The project throws no errors until I build the project, at that time it tells me "Build Succeeded" then tells me the below error. When I navigate to the path, I can get to the following directory however, there is no further file there...
/Users/PROFILE/Library/Developer/CoreSimulator/Devices/DEVICE_UUID/data/Library/Caches/com.apple.mobile.installd.staging
I have ensure that the Info.plist is in the directory. I have also verified that the path is proper via the Build Settings.
Please try again later.
Failed to load Info.plist from bundle at path /Users/PROFILE/Library/Developer/CoreSimulator/Devices/DEVICE_UUID/data/Library/Caches/com.apple.mobile.installd.staging/temp.z14Qmt/extracted/HealthCalc.app/Frameworks/GoogleMobileAds.framework;
Extra info about "/Users/PROFILE/Library/Developer/CoreSimulator/Devices/DEVICE_UUID/data/Library/Caches/com.apple.mobile.installd.staging/temp.z14Qmt/extracted/HealthCalc.app/Frameworks/GoogleMobileAds.framework/Info.plist":
Couldn't stat /Users/PROFILE/Library/Developer/CoreSimulator/Devices/DEVICE_UUID/data/Library/Caches/com.apple.mobile.installd.staging/temp.z14Qmt/extracted/HealthCalc.app/Frameworks/GoogleMobileAds.framework/Info.plist: No such file or directory
While a root cause has not been determined for these errors. I have been able to fix my issues via reimporting and reinstalling the Google AdMob Manual SDK all together.
In doing so I followed the Manual SDK Instructions, particularly I believe the root issue was some funky indentation or mishap in the Info.plist. That being said, if you run into a similar issue, I urge you to take a step back. Start a fresh blank project and attempt to implement the Google AdMob procedures in the blank project. This will eliminate the concern that your current code is causing any conflicts. Once completed and you have it working, mimic the steps within your core project.
I recently changed over to Android Studio from Eclipse and when starting new projects with a blank activity template have come across the following message in my main layout xml file
I looked up SO and tried the following solutions:
*Raising the minSDK in the build.gradle file - it raised additional problems of missing styles
*Trying to update Android Studio - I was up-to-date even in the "Canary" setting
*Reducing the API level of the layout - when I went down to API 22, the image disappeared altogether.
In Eclipse, I would go to Properties/Android and see if anything needed to be updated, or go to Build Path to see if it looked OK.
What can I do here? Thanks:)
I have just found an answer on SO that worked for me. (I am sorry but I haven't figured out how to quote the question no.)
I also got this problem today,
Check your build.gradle file, do you use support design lib version
23.2, like
compile 'com.android.support:design:23.2.0' if so, change it to
version 23.1.0
compile 'com.android.support:design:23.1.0' then rebuild your
project... seems version 23.2 is still buggy
I'm following this:
http://docs.gstreamer.com/display/GstSDK/Installing+for+Android+development
I'm using the Windows x86 ADT bundle, the Windows x86 r9d NDK, and the Gstreamer SDK linked to in the guide.
I was able to get the first tutorial to add native support, build, and run. Then I tried the 3rd tutorial, and Eclipse becomes unresponsive. Same thing happened with the 2nd tutorial. I left it to do it over the weekend in case it just took a long time. When I change anything for another attempt I delete the tutorial folder completely and use a fresh copy from the zip file. I have also remove the ADT bundle completely and started over from scratch.
If I cancel, I have the expected build errors of missing import com.gstreamer.GStreamer;
The GSTREAMER_SDK_ROOT_ANDROID value is set to C:/gstreamer
The NDK Location is C:\android-ndk-r8d
I switched to using r8d as recommended in: Adding Gstreamer support to an android NDK project
One comment also suggests adding to the gstreamer.mk file:
ifndef SYSROOT
SYSROOT := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH)
endif
I attempted this but there is a gstreamer_prebuilt.mk file it may be using instead.
My only clue is that Tutorial 1 does not use gstreamer plugins and the tutorials that do not work use plugins.
Thank you for any help you can give.
Edit: I tried using android-ndk-r7c also.
Then I deleted the ADT bundle and tried going the "Use an existing IDE" route, same result.
I'm going to try a different machine, and also see if I can compile it without eclipse, but I would love to hear any guess on what's going on.
Edit2: I watched a youtube video of someone setting this up (as far as I can tell he adds the NDK manually adding a build program and pointing to the ndk-build.cmd file):
https://www.youtube.com/watch?v=nKfAELFdf9A
This seemed to work but I was still missing import com.gstreamer.GStreamer; so I closed the tutorial 2 project, built and ran tutorial 1, opened tutorial 2 again, cleaned, built, and it ran.
Problem solved.
I watched a youtube video of someone setting this up (as far as I can tell he adds the NDK manually adding a build program and pointing to the ndk-build.cmd file):
https://www.youtube.com/watch?v=nKfAELFdf9A
This seemed to work but I was still missing import com.gstreamer.GStreamer; so I closed the tutorial 2 project, built and ran tutorial 1, opened tutorial 2 again, cleaned, built, and it ran.
Problem solved.
With Vuforia's ImageTargets sample application, I tried using OpenGL ES 1.1 by setting USE_OPENGL_ES_1_1 to true in jni/Android.mk and uncommenting and changing the corresponding line in AndroidManifest.xml (). After converting the project so that it has a C++ perspective and associating ndk-build and the proper include directories, I could successfully run the application on my Android device.
However, the problem is that once I open up jni/ImageTargets.cpp, I get several errors from Eclipse, all from places where OpenGL ES 2.0 code would execute, the first one being:
Description Resource Path Location Type Symbol 'vertexHandle' could
not be resolved ImageTargets.cpp /ImageTargets/jni line 402 Semantic
Error
Sure enough, vertexHandle is defined at the top of the ImageTargets.cpp, inside the "#ifdef USE_OPENGL_ES_2_0" block. Because USE_OPENGL_ES_2_0 is not defined (per Android.mk), the code should be able to compile successfully, and sure enough, ndk-build does not report any problems. So it seems that only Eclipse reports the problems and when I run the project, Eclipse says, "Your project contains error(s), please fix them before running your application." And thus, I cannot run my application anymore. In a sense, it's kind of strange that this never occurred until I opened ImageTargets.cpp and Eclipse "discovered" the errors.
The best work-around I've found so far is to just delete or comment out those lines (that should not be causing problems because USE_OPENGL_ES_2_0 is not supposed to be defined)... Is there a better way to deal with this problem? Did I miss a setting in Eclipse that should solve this?
I've found a solution: go to the project properties -> C/C++ Build -> Discovery Options -> Check "Automate discovery of paths and symbols"
I am using Eclipse for Android dev and everything was going fine until I tried to incorporate the facebook SDK. Now when I tried to back it out, there appears to be an artifact left behind that Eclipse tries to link the FB library?!?
[2010-11-17 18:50:22 - Library Project] Unable to set linked path var '_android_com.facebook.android' for library /Users/mobibob/Projects/workspace/facebook-android-sdk/facebook: Path variable name cannot contain character: ..
Any clue where this command / reference is in the build configuration? I have scoured it as best that I can, but I still get the same error.
Problem solved ... as it turns out, it was not so much the Facebook SDK but something that I did in the process of configuring the library reference. I am not entirely certain of how I misconfigured, but I was tweaking the various "path" settings such that, once when the automatic build tried to build my project, an import for android.R was added to my source module. This superseded com.myproject.R and would not resolve the values for resource references.
There were other problems with path order and setting that I modified during the troubleshooting that made it worse. Recreating the project without Facebook was the first step to discovery and fixing.
Either way, the lesson I learned is that the build error messages can misdirect one to the configuration when the problem is in the source code.