Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by manasjg · Oct 22, 2021 at 11:04 AM · androidpluginloginamazon

Getting NoClassDef Found Error when creating android plugin for amazon login

I was trying to integrate the LWA (Login With Amazon) SDK into a sample unity project that I created. but I am getting the following error when I created the APK from Unity. Is it a versioning problem?

2021-10-22 14:52:45.800 17549-17578/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/FragmentActivity; java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/FragmentActivity; at com.amazon.identity.auth.device.api.workflow.RequestContext.create(RequestContext.java:73) at com.example.unityamazonplugin.AmazonPlugin.SetupSDK(AmazonPlugin.java:27) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.c(Unknown Source:0) at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:236) at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) Caused by: java.lang.ClassNotFoundException: android.support.v4.app.FragmentActivity at com.amazon.identity.auth.device.api.workflow.RequestContext.create(RequestContext.java:73) at com.example.unityamazonplugin.AmazonPlugin.SetupSDK(AmazonPlugin.java:27) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.c(Unknown Source:0) at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:236) at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) at UnityEngine.AndroidJNISafe.CheckException () [0x00091] in :0 at UnityEngine.AndroidJNISafe.CallVoidMethod (System.IntPtr obj, System.IntPtr method

Plugin Class Code -

 package com.example.unityamazonplugin;
 
 import android.content.Context;
 import android.util.Log;
 
 import com.amazon.identity.auth.device.AuthError;
 import com.amazon.identity.auth.device.api.authorization.AuthCancellation;
 import com.amazon.identity.auth.device.api.authorization.AuthorizationManager;
 import com.amazon.identity.auth.device.api.authorization.AuthorizeListener;
 import com.amazon.identity.auth.device.api.authorization.AuthorizeRequest;
 import com.amazon.identity.auth.device.api.authorization.AuthorizeResult;
 import com.amazon.identity.auth.device.api.authorization.ProfileScope;
 import com.amazon.identity.auth.device.api.workflow.RequestContext;
 
 public class AmazonPlugin {
 
     public static final  AmazonPlugin pluginInstance = new AmazonPlugin();
     public static AmazonPlugin getInstance() { return  pluginInstance;}
     private boolean loginSuccessful = false;
     private RequestContext requestContext;
     private AmazonPlugin(){
         Log.i("Xansr", "Created Log Plugin");
     }
 
 
     public void SetupSDK(Context unityContext){
         requestContext = RequestContext.create(unityContext);
         requestContext.registerListener(new AuthorizeListener() {
 
             /* Authorization was completed successfully. */
             @Override
             public void onSuccess(AuthorizeResult result) {
                 /* Your app is now authorized for the requested scopes */
                 Log.i("Log", "Logged in success " + result.getUser().getUserEmail());
                 loginSuccessful = true;
             }
 
             /* There was an error during the attempt to authorize the
             application. */
             @Override
             public void onError(AuthError ae) {
                 /* Inform the user of the error */
                 Log.i("Log", "Logged in error");
             }
 
             /* Authorization was cancelled before it could be completed. */
             @Override
             public void onCancel(AuthCancellation cancellation) {
                 /* Reset the UI to a ready-to-login state */
                 Log.i("Log", "Logged in cancel");
             }
         });
     }
 
     public boolean isUserLoggedIn(){
         return  loginSuccessful;
     }
 
     public void LoginPressed(){
         AuthorizationManager.authorize(new AuthorizeRequest
                 .Builder(requestContext)
                 .addScopes(ProfileScope.profile(), ProfileScope.postalCode())
                 .build());
     }
 
 }

Unity Code -

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using TMPro;
 
 public class PluginTest : MonoBehaviour
 {
     const string pluginName = "com.example.unityamazonplugin.AmazonPlugin";
     static AndroidJavaClass _pluginClass;
     static AndroidJavaObject _pluginInstance;
     public Button LoginButton;
     public TextMeshProUGUI LoggedInText;
     public static AndroidJavaClass PluginClass
     {
         get
         {
             if(_pluginClass == null)
             {
                 _pluginClass = new AndroidJavaClass(pluginName);
             }
             return _pluginClass;
         }
     }
 
     public static AndroidJavaObject PluginInstance
     {
         get
         {
             if (_pluginInstance == null)
             {
                 _pluginInstance =PluginClass.CallStatic<AndroidJavaObject>("getInstance");
             }
             return _pluginInstance;
         }
     }
     // Start is called before the first frame update
     void Start()
     {
         LoginButton.onClick.AddListener(CheckAndSetLogin);
         SetupSDK();
     }
 
     void SetupSDK()
     {
         if (Application.platform == RuntimePlatform.Android)
         {
             AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
             AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
             PluginInstance.Call("SetupSDK", activity);
         }
     }
     void CheckAndSetLogin()
     {
         if (Application.platform == RuntimePlatform.Android)
         {
             PluginInstance.Call("LoginPressed");
             StartCoroutine(StartCheckingForLogin());
         }
     }
 
     IEnumerator StartCheckingForLogin()
     {
         yield return new WaitUntil( () => PluginInstance.Call<bool>("isUserLoggedIn"));
         LoggedInText.gameObject.SetActive(true);
         LoginButton.gameObject.SetActive(false);
     }
 }

build.gradle -

 apply plugin: 'com.android.library'
 
 android {
     compileSdkVersion 29
     buildToolsVersion "31.0.0"
 
     defaultConfig {
         minSdkVersion 16
         targetSdkVersion 29
         versionCode 1
         versionName "1.0"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         consumerProguardFiles "consumer-rules.pro"
     }
 
     buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }
 }
 
 dependencies {
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation 'androidx.appcompat:appcompat:1.3.1'
     implementation files('libs\\login-with-amazon-sdk.jar')
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
 
 }
 
 task copyPlugin(type: Copy){
     dependsOn assemble
     from('build/outputs/aar')
     into('../../../../../Assets/Plugins/Android')
     include(project.name + '-release.aar')
 }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DrHerringbone · Oct 29, 2021 at 12:19 AM 0
Share

I am also having a very similar issue with a plugin that I made. I even exported the project and looked in the external library folder and there is my plugin, along with the class that is supposedly missing. Did you ever find a fix?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

281 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Are apps with unity ads allowed in amazon app store?? 1 Answer

How to integrate new google play games services for leaderboard? 2 Answers

Android obfuscator 1 Answer

YouTube Player Fragment in Plugin 1 Answer

Where can I find the resource definition for google play games android configuration? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges