Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building issue #1

Open
ItsAntiUp opened this issue Mar 17, 2018 · 10 comments
Open

Building issue #1

ItsAntiUp opened this issue Mar 17, 2018 · 10 comments

Comments

@ItsAntiUp
Copy link

Hello, this plugin is really simple and awesome, but when i try to build it in unity it gives me this error:
CommandInvokationFailure: Failed to re-package resources.
C:\Users\Vartotojas\AppData\Local\Android\sdk\build-tools\25.0.3\aapt.exe package --auto-add-overlay -v -f -m -J "gen" -M "AndroidManifest.xml" -S "res" -I "C:/Users/Vartotojas/AppData/Local/Android/sdk\platforms\android-25\android.jar" -F bin/resources.ap_ --extra-packages com.hiyorin.googlesignin:com.area730.localnotif:com.google.android.gms.auth.api:com.google.android.gms.auth -S

Does someone know what to do? Thanks in advance!

@ItsAntiUp
Copy link
Author

I think this is the main error:

stderr[
AndroidManifest.xml:18: error: Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

]

@hiyorin
Copy link
Owner

hiyorin commented Mar 19, 2018

Thanks! Fixed it.

@ItsAntiUp
Copy link
Author

Oh wow! That was really fast. Thanks! I can now build my project to phone. There is still one problem, on PC it works perfectly, but on phone it doesn't. I try to figure this out by myself, as you already helped me quite alot :) Thanks again.

@ItsAntiUp
Copy link
Author

Alright, what i figured out is that the signin on android phone stops working after the androidjavaclass is initialized. Maybe the class name is wrong? (com.hiyorin.googlesignin.GoogleSinInPlugin)

@hiyorin
Copy link
Owner

hiyorin commented Mar 21, 2018

Class name is com.hiyorin.googlesignin.GoogleSignInPlugin.
Please check the GoogleSignInPluginForAndroid class.

@ItsAntiUp
Copy link
Author

In GoogleSignInPluginForAndroid everything seems to be okay. Maybe something is wrong with this GoogleSignInPlugin file?

package com.hiyorin.googlesignin;
import android.content.Intent;
public class GoogleSignInPlugin
{
public static final String TAG = "GoogleSignInPlugin";
public static final String SIGN_IN_SUCCESSED_CALLBACK = "OnSignInSuccessed";
public static final String SIGN_IN_FAILED_CALLBACK = "OnSignInFailed";
public static final String SIGN_IN_USER_CANCEL_CALLBACK = "OnSignInUserCancel";
public static GoogleSignIn instance = null;
public static GoogleSignIn Instance()
{
if (instance == null)
instance = new GoogleSignIn();
return instance;
}
public static void initialize()
{
Instance().initialize();
}
public static void dispose()
{
Instance().dispose();
}
public static void signIn(String clientId,
boolean requestEmail,
boolean requestId,
boolean requestIdToken,
boolean requestServerAuthCode,
boolean requestProfile)
{
Instance().signIn(clientId, requestEmail, requestId, requestIdToken, requestServerAuthCode, requestProfile);
}
public static void signOut()
{
Instance().signOut();
}
public static void setDebugMode(boolean isEnable)
{
Instance().setDebugMode(isEnable);
}
public static void onActivityResult(int requestCode, int resultCode, Intent data)
{
Instance().onActivityResult(requestCode, resultCode, data);
}
public static String getEmail() { return Instance().getEmail(); }
public static String getId() { return Instance().getId(); }
public static String getIdToken() { return Instance().getIdToken(); }
public static String getServerAuthCode() { return Instance().getServerAuthCode(); }
public static String getDisplayName() { return Instance().getDisplayName(); }
}

Or this GoogleSignInFile?

package com.hiyorin.googlesignin;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.auth.api.signin.GoogleSignInStatusCodes;
import com.google.android.gms.common.api.GoogleApiClient;
import com.unity3d.player.UnityPlayer;
public class GoogleSignIn implements Application.ActivityLifecycleCallbacks
{
private static final int RC_SIGN_IN = 9001;
private GoogleApiClient client = null;
private GoogleSignInAccount accont = null;
private boolean isDebugMode = false;
public String getEmail() { return accont != null ? accont.getEmail() : ""; }
public String getId() { return accont != null ? accont.getId() : ""; }
public String getIdToken() { return accont != null ? accont.getIdToken() : ""; }
public String getServerAuthCode() {return accont != null ? accont.getServerAuthCode() : ""; }
public String getDisplayName() {return accont != null ? accont.getDisplayName() : ""; }
public void initialize() {
UnityPlayer.currentActivity.getApplication().registerActivityLifecycleCallbacks(this);}
public void dispose() {
UnityPlayer.currentActivity.getApplication().unregisterActivityLifecycleCallbacks(this);
}
public void signIn(String clientId,
boolean requestEmail,
boolean requestId,
boolean requestIdToken,
boolean requestServerAuthCode,
boolean requestProfile)
{
Log.d(GoogleSignInPlugin.TAG, String.format("signIn clientId:%s, requestEmail:%b, requestId:%b, requestIdToken:%b, requestServerAuthCode:%b, requestProfile:%b",
clientId, requestEmail, requestId, requestIdToken, requestServerAuthCode, requestProfile));

GoogleSignInOptions.Builder builder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);

if (requestEmail) builder.requestEmail();
if (requestId) builder.requestId();
if (requestIdToken) builder.requestIdToken(clientId);
if (requestServerAuthCode) builder.requestServerAuthCode(clientId);
if (requestProfile) builder.requestProfile();

GoogleSignInOptions options = builder.build();
Activity currentActivity = UnityPlayer.currentActivity;
client = new GoogleApiClient.Builder(currentActivity)
.addApi(Auth.GOOGLE_SIGN_IN_API, options)
.build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(client);
currentActivity.startActivityForResult(signInIntent, RC_SIGN_IN);
}
public void signOut()
{
logDebug("signOut", "");
if (client != null)
{
if (client.isConnected())
{
Auth.GoogleSignInApi.signOut(client);
client.disconnect();
}
client = null;
}
}
public void setDebugMode(boolean isEnable)
{
logDebug("setDebugMode", String.format("isEnable:%b", isEnable));
isDebugMode = isEnable;
}
private void onSignInResult(GoogleSignInResult result)
{
if (result.isSuccess())
{
logDebug("onSignInResult", "successed");
accont = result.getSignInAccount();
client.connect();
UnityPlayer.UnitySendMessage(GoogleSignInPlugin.TAG, GoogleSignInPlugin.SIGN_IN_SUCCESSED_CALLBACK, "");
}
else if
(result.getStatus().getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED)
{
logDebug("onSignInResult", "user cancel");
UnityPlayer.UnitySendMessage(GoogleSignInPlugin.TAG, GoogleSignInPlugin.SIGN_IN_USER_CANCEL_CALLBACK, "");
}
else
{
logError("onSignInResult", String.format("failed %s", result.getStatus().toString()));
UnityPlayer.UnitySendMessage(GoogleSignInPlugin.TAG, GoogleSignInPlugin.SIGN_IN_FAILED_CALLBACK, result.getStatus().toString());
}
}
private void logDebug(String method, String message)
{
if (isDebugMode)
{
Log.d(GoogleSignInPlugin.TAG, String.format("%s %s", method, message));
}
}
private void logError(String method, String message)
{
if (isDebugMode)
{
Log.e(GoogleSignInPlugin.TAG, String.format("%s %s", method, message));
}
}
/**
* Call Activity lifecycle onActivityResult
* @param requestCode
* @param resultCode
* @param data
*/

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
logDebug("onActivityResult", String.format("requestCode:%d, resultCode:%d", requestCode, resultCode));

if (requestCode == RC_SIGN_IN)
{
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
onSignInResult(result);
}
}

@OverRide
public void onActivityCreated(Activity activity, Bundle savedInstanceState)
{

}

@OverRide
public void onActivityStarted(Activity activity)
{

logDebug("onActivityStarted", "");

if (client != null)
{

client.connect();

}

}

@OverRide
public void onActivityResumed(Activity activity) {

}

@OverRide
public void onActivityPaused(Activity activity) {

}

@OverRide
public void onActivityStopped(Activity activity) {

logDebug("onActivityStopped", "");
if (client != null && client.isConnected())
{
client.disconnect();

}

}

@Override

public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

}

@OverRide
public void onActivityDestroyed(Activity activity) {

}

}

@hiyorin
Copy link
Owner

hiyorin commented Mar 24, 2018

Thanks! Fixed it.
There was a problem with plugin initialization.

@ItsAntiUp
Copy link
Author

You know, I'm really thankful to you, because you find the time to help people like me, who experiences issues. I hate to say this but i really can't seem to get it working on android phone.

    private void Start()
    {
        GameObject.Find("Status").GetComponent<Text>().text = "1";
        GameObject.Find("Status").GetComponent<Text>().text =  new AndroidJavaClass(ClassName).ToString();
        using (AndroidJavaClass plugin = new AndroidJavaClass(ClassName))
        {
            GameObject.Find("Status").GetComponent<Text>().text = "2";
            plugin.CallStatic("initialize");
            GameObject.Find("Status").GetComponent<Text>().text = "3";
        }
    }

text "1" appears right away, but "2" and "3" never does.

Thanks for your time and effort for making this plugin :)

@hiyorin
Copy link
Owner

hiyorin commented Mar 25, 2018

Sorry, Not reproduce.

GoogleSignInPluginForAndroid

        private void Awake()
        {
            using (AndroidJavaClass plugin = new AndroidJavaClass(ClassName))
            {
                Debug.Log("Initialize 01");
                plugin.CallStatic("initialize");
                Debug.Log("Initialize 02");
            }
        }

Text "initialize 01", "initialize 02" appears right away.
I hope your problem will be solved.

@ItsAntiUp
Copy link
Author

Alright, I'm back again :) So I tried "prebuild with gradle" On GooglePlayServicesResolver and it gave me this error:

Error somewhere in the process of creating the gradle build, executing it, and copying the outputs.
This will break dependency resolution and your build will not run.
See the output below for possible gradle build errors. The most likely cases are: an invalid bundleID (which you can correct in the Android Player Settings), or a failure to determine the Android SDK platform and build tools verison (you can verify that you have a valid android SDK path in the Unity preferences.
If you're not able to diagnose the error, please report a bug at: https://github.com/googlesamples/unity-jar-resolver/issuesA possible work-around is to turn off the "Gradle Prebuild" from the Jar Resolver Settings.

Error (-1):
Traceback (most recent call last):
File "", line 475, in
File "", line 466, in main
File "", line 460, in process_args
Exception: The "project_deps" section of the json config file is missing. See sample/sampledeps.json.
generate_gradle_prebuild returned -1

UnityEngine.Debug:LogError(Object)
GooglePlayServices.c__AnonStoreyE:<>m__11(Result)
GooglePlayServices.ProgressReporter:Update(CommandLineDialog)
GooglePlayServices.CommandLineDialog:Update()
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Maybe there's a problem somewhere in there? Thanks in advance :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants