FB.Init() error during gradle build unity - facebook

I am using Unity 2018.1.6f1 and facebook-unity-sdk-7.13.0. When I try to build the project using gradle, the build is completed successfully but it gives an error while calling FB.Init()
"AndroidJavaException: java.lang.ClassNotFoundException:
com.facebook.unity.FB".
I tried the solution in the following links:
Android ProGuard settings for Facebook
I even checked whether I was using debug keyhash, which I was, but I addded release key hash and still getting the same error.
Any help would be appreciated.
P.S. It works fine in debug build

On Android publishing settings section (in the place you set the keystore stuff), there is a checkbox for User ProGuard file (at least if you are on Gradle). If you check it, Unity will make such file and put it in the project.
Then, on the proguard file, I added:
-keep class com.facebook.** { *; }
-keepattributes Signature
And that seems to be all!
Then I see the FB SDK initing properly both on Debug and Release:
Hope it works for you as well.

Related

Unity Asset Bundles Google Play Asset Delivery - Proguard Minification

I am having problems configuring Proguard to prevent minification of java libraries in the Google Play Asset Bundles and Asset Delivery Plugins when building a .aab using the Google Android App Bundle Unity Editor tool, using the following configuration:
Build Settings:
Create Symbols.zip - Debugging
Compression Method - LZ4
Project Settings - Player - Other:
API minimum - 5
Target API - 33
Scripting Backend - IL2CPP (.NET Standard 2.1)
IL2CPP Generation - Fastest
ARMv7 & ARM64
Strip Engine Code - true
Publishing Settings:
Custom Proguard file
Minify:
R8 - false
Release - true
The custom Proguard file in Assets\Plugins\Android:
-keep public class com.google.play.core.**{
public *;
}
-keep public class com.google.play.common.**{
public *;
}
-keep public class com.google.play.appbundle.**{
public *;
}
-keep public class com.google.play.assetdelivery.**{
public *;
}
-keepattributes *Annotation*
-dontobfuscate
This is linked form the mainTemplate.gradle build file.
Building this with the Google Editor Plugin continues to strip out both Methods and Interfaces resulting in the app crashing on start-up. I have tested the above Proguard by introducing each element which corrects some issues, but is still removing Interfaces from play.core.
Note: I have not included Stack Traces as they are pointing to specific methods and Interfaces in the Plugin libraries which were incrementally fixed by adding each exception to the Proguard file above, but is still not preserving all functions.
I have followed multiple other threads stating the same issue which suggested - deleting the library folder, using custom .gradle, downgrading all of the Google Plugins (1.7.0 release). This had previously worked using R8, but I have not been able to produce a working build since the new updates.
I have also tried multiple combinations of builds but continue to get the same issue to varying degrees of what is and is not kept, all builds cause the app to crash.
Any help in the Proguard configuration or suggestions in build configuration would be greatly appreciated, as this seems to be a popular topic with no clear solution. I am trying not export the project and build in Android Studio as that would be a significant break from our current build process.
If there is any more information I can provide please let me know.
Thanks everyone.
UPDATE: The above issue is not to do with Proguard settings.
Copying in the Proguard settings from the google.play. plugins in to a proguard-user.txt file did not fix the issue as the files were not being correctly handled during gradle build.
R8 minification was not enabled and should have been. The underlying issue is conflicts in class dependencies in the google.play plugins. Specifically;
Assets/GooglePlayPlugins/com.google.play.assetdelivery 2.0.0
Assets/GooglePlayPlugins/com.google.play.core 1.10.3
This is a documented issue in play-unity-plugins for google;
https://github.com/google/play-unity-plugins/blob/master/README.md#play-core-conflicts
However, their fix in the link is proving difficult to implement as I am unfamiliar with gradle and using local maven repositories, and difficulties with EDM4U build patching.
I have started a new thread on the issue;
Unity google.play.core dependency conflict with EDM4U maven local repository build error

Fatal Crash when using Unity to call startMoniting from AAR file

I use the android-beacon-library-2.17.1.aar to make an Android App and detect the ibeacon's major/minor numbers. When I call beaconManager.startMonitoring(new Region("myMonitoringUniqueId", null, null, null)); the App runs well. And I make the program I design to the classes.jar file.
Now I use Unity and try to use this jar file to detect the ibeacon on my Unity Android Application. I put the classes.jar and AndroidManifest.xml in to my Unity project and try to call the beaconManager.startMonitoring(new Region("myMonitoringUniqueId", null, null, null)); the compile and Build are passed, but when I install the apk on my phone and run it, the application crash.
The Phone I use: Zenfone 7 -- Android 11
The version of Unity: Unity2019.4.31f1
The error log:
java.lang.NoSuchMethodError: No virtual method startRangingBeacons(Lorg/altbeacon/beacon/Region;)V in class Lorg/altbeacon/beacon/BeaconManager; or its super classes (declaration of 'org.altbeacon.beacon.BeaconManager' appears in /data/app/~~lOm13WWD8uZ_nbS2pIVb3A==/com.example.aartesting-LqhAFNQZtBYPkoICvZt1ig==/base.apk)
It's sorry that my English is not very well, and I afraid that I can't describe my problem clearly. If you want to know more about my problem, please let me know, I will try to make you know more about the situation I met.
Thank you!
I suspect the problem is caused by R8 or ProGuard settings, which obfuscate code to prevent reverse engineering. Aggressive R8 or ProGuard settings will rename certain classes and methods (including library class methods like startRangingBeacons mentioned in the stack trace).
You can read more about how R8 and ProGuard work here: https://developer.android.com/studio/build/shrink-code
To confirm this is the problem, you should edit your project settings for Android to disable R8 and ProGuard. Doing so for a native Android project is as simple as editing the build.gradle file and setting minifyEnabled false. Since I am not a Unity expert, I cannot tell you how to do the same thing from Unity.

Add plain Android library to a Flutter plugin

This might be a duplicate of this question. But it has no answer and I will give some details here.
I have created a module with File->New Module->Android Library inside my Flutter plugin's android project. And now I have a structure like below:
|-my_plugin
|-android
|-settings.gradle
|-build.gradle
|-mylibrary
|-build.gradle
/android/settings.gradle:
rootProject.name = 'my_plugin'
include ':mylibrary'
/android/build.gradle:
...
dependencies {
implementation project(':mylibrary')
}
When I build example plugin project (which is automatically created by Flutter CLI) with flutter build apk or flutter run, I get this error:
Project with path ':mylibrary' could not be found in project ':my_plugin'.
Any suggestions?
For those who are still looking for a solution. You can try this.
Instead of putting the below code in the plugin setting.gradle, place it in example/android/settings.gradle
include ':mylibrary'

Error in Build After InAppPurchase Unity

CommandInvokationFailure: Unable to merge android manifests. See the Console for more details.
C:/Program Files/Java/jdk1.8.0_161\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Users/Sabasoft Developer/Downloads/tools_r25.2.3-windows\tools" -Dfile.encoding=UTF8 -jar "D:\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -
stderr[
]
stdout[
Warning: [Temp\StagingArea\AndroidManifest-main.xml:12, D:\unity projects\Pizza maker\Temp\StagingArea\android-libraries\GooglePlay\AndroidManifest.xml:3] Main manifest has but library uses targetSdkVersion='24'
]
exit code: 1
Update Java SdK
Update Android SdK
Check target in menifest file and Unity editor. Both should be same.
Remove duplicate .jar under plugins folder if there are any.
You are using a library somewhere in your code (possibly something for GooglePlay?). The library has a manifest.xml file that is likely located in a folder called plugin or one of its subfolders.
The manifest is the file used by android to describe the app: how it starts, what permissions it has, and so on.
Any android project in unity will include a default manifest.xml file. This file is edited by unity with some info relative to you game (the name, and the target version, are part of it).
Now, the libraries you include in your project might need different options and values in the manifest, so Unity libraries for android usually come with another manifest.xml file. This will will be automatically merged with the default one by unity at build time.
Usually, it goes well, the additional line in the manifest from the library get added to the default manifest.
But in your case, there is a conflict between these manifests. The target version is specified both in the library and in your project. So unity can't resolve it.
To fix this, use a target version for your project that is the same or higher than the one of the library. Edit your target version under player settings

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script7.groovy: 1: unable to resolve class

I am currently receiving this error when trying to run a soapui file:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: Script7.groovy: 1: unable to resolve class com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate # line 1, column 1.
import com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate # line 1, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:148)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1206)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:148)
at org.codehaus.groovy.control.CompilationUnit$6.call(CompilationUnit.java:585)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:832)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:519)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:495)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:472)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:292)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:141)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
1 error
soapUI code:
import com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate
def env = testRunner.testCase.testSuite.project.getPropertyValue("env")
def baseUrl = testRunner.testCase.testSuite.project.getPropertyValue("baseUrl")
log.info("The baseurl is "+baseUrl)
log.info("The env under test is "+env)
SoapUI_T11001_StockConsSecurityCurBusiDate testStep = new SoapUI_T11001_StockConsSecurityCurBusiDate();
testStep.init(baseUrl);
testStep.execute(null);
eclipse code:
package com.company.ui.test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.eviware.soapui.model.support.AbstractSubmitContext;
import com.eviware.soapui.model.testsuite.TestRunner;
public class SoapUI_T11001_StockConsSecurityCurBusiDate extends BaseSelenium{
public static void main(final String[] args){
final SoapUI_T11001_StockConsSecurityCurBusiDate ico = new SoapUI_T11001_StockConsSecurityCurBusiDate();
try{
ico.init("https://avncedevn1.nam.nsroot.net:17620/", false);
}catch(Exception e){
// TODO Auto-generated catch block
e.printStackTrace();
}
ico.execute(null);
}
//...code....
}
how do I solve this error ? I'm not sure what is causing the error.
This work for me:
Press Ctr+Alt+Shift+s
or:
From File menu -> Project Structure -> SDK Location -> JDK location Drop down menu choose:
Embeded JDK c:....\jre
Then ok.
If you using android studio and got this error then I solved it changing the Gradle version of the project to the newest version 6.2.1 on the project structure options.
One of the possible reasons is that the jdk version is too high. For example, using jdk 16 to build the source code of Apache Kafka throws this error. Using jdk 11 is fine.
bild.gradel file in change clashpath
dependencies {
classpath "com.android.tools.build:gradle:7.0.1"
}
gradel-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
I'm Using Android Studio - Arctic Fox and this worked for me
Go To File menu -> Project Structure -> SDK Location -> Gradle Setting
Then check the "Download external annotations for dependencies" button and select JDK location from the drop down menu and choose: Android Default Jdk Vesion.
Click on Ok.
If you wanted to make a new project on Android Studio after first install, probably you write your application name including (') sign as called apostrophe.
For Example, I tried to set a name as: "Henry's Game" but apostrophe caused Android Studio to not load because of this mistake:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
So, just change your application's name, and simply use Latin alphabet languages such as English.
To fix: Go to your Android Project Tree and find Gradle Scripts > settings.gradle > change the name:
rootProject.name='Henry Game'
include ':app'
With Eclipse Juno (Kepler Release) Build id: 20121114-2344, I found similar problem:
org.codehaus.groovy.control.multiplecompilationerrorsexception startup failed unable to resolve class Chart
The class Chart is my container class for some utilities for charting.
I tried outside of Eclipse, with Groovy 2.0 Console the same code segment works fine. After scratching my head for about 3 hours, I resolved it by adding the following
import excel.Chart
in the invoking class with main() that has "new Chart()" thus getting the complaints, once added, the error is gone. Even more weird, after passing the error, I remove that import, there is still no more complaints! (All my scripts/classes are under the same package excel, I suppose such import statement is not needed.)
One of the symptom of the complaints is that there was not Chart.class generated in the output bin folder. Once the complaints gone, Chart.class appeared there.
I guess that it might be a bug of Eclipse/Groovy plugin (I use Groovy Plugin for Juno).
Hope my understanding is correct, and it helps.
The solution for me was change the gradle version and the Gradle JDK:
File > Project Structure > Project
enter image description here
File > Project Structure > SDK Location
enter image description here
Go to Files and click Invalidate caches/ Restart . Android studio will clear the cached and it will be restarted without any error.
Hope this answer helps you :)
For this problem, you might also encounter package naming from gsp as I did. In the build/gsptmp folder, Grails 4.x.x creates temporary gsp files to link the classes that they refer to. Due to the change of a package name it was failing to do so in my case. Try with command grails war --stacktrace during war build!
Previously, it was <%# page import="bv.BankReconciliationController" %>
but the folder bv was renamed to factoring.
So, the solve was to change the import to
<%# page import="factoring.BankReconciliationController" %> and it worked :)
I have also faced the same and tried all of the solution here and other places as well, at last i deleted my .gradle and gradle both folder and caches of android studio and open the studio again and rebuild the project, it's works after that fine and used the latest gradle version and previously it was picking up the older version and causing issues.
for me , solution is to upgrade the gradle to latest version , and remove the .idea file , and invalidate caches and restart android studio.
When starting a project make sure to select SDK version 11 or later. It will default to a minimum SDK but you have to scroll down to a later version for it to work. Then the project should load and build.
For me, I just delete the .grade file under program files(C:\Users\username\ .gradle) in windows and it will work.
This work for me:
From File menu -> Project Structure -> SDK Location -> klik Gradle Setting for show hide menu, Gradle JDK choose:
Embeded JDK c:....\jre
Then ok.
Do you have the grail and groovy plugin installed? If so try uninstalling this plugin. I had the same error message and uninstalling the plugin, restart IDE worked for me.