Android Question GoogleApiAvailability Issue on New Android SDK GUI

Discussion in 'Android Questions' started by Azam Memon, Dec 23, 2017.

  1. Azam Memon

    Azam Memon Member Licensed User

    I am using Firebase Analytics and Firebase Ads services in my app.

    Before B4A version 7.8, I was using old GUI based Android SDK Manager and my code was working fine. I have updated to B4A version 7.8 and used new Android SDK available with B4A 7.8 and installed all recommended as well as other tools like Google Repository, Google APIs v20, and Google Play Services.

    My app is compiling and when I am running my app on Android Device, I am getting an error about ClassNotFoundException.

    Code:
    *** Service (starter) Create ***
    starter_checkforgoogleplayservices (java line: 
    178)
    java.lang.ClassNotFoundException: com.google.android$gms$common$GoogleApiAvailability
        at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(
    JavaObject.java:288)
        at anywheresoftware.b4j.object.JavaObject.InitializeStatic(
    JavaObject.java:74)
        at com.galaxy.wireless_conversation.starter._checkforgoogleplayservices(starter.java:
    178)
        at com.galaxy.wireless_conversation.starter._service_create(starter.java:
    548)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    186)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    166)
        at com.galaxy.wireless_conversation.starter.onCreate(starter.java:
    55)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:
    3807)
        at android.app.ActivityThread.access$
    2100(ActivityThread.java:223)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
    1882)
        at android.os.Handler.dispatchMessage(Handler.java:
    102)
        at android.os.Looper.loop(Looper.java:
    148)
        at android.app.ActivityThread.main(ActivityThread.java:
    7223)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1120)
    java.lang.RuntimeException: Unable 
    to create service com.galaxy.wireless_conversation.starter: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.google.android$gms$common$GoogleApiAvailability
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:
    3817)
        at android.app.ActivityThread.access$
    2100(ActivityThread.java:223)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
    1882)
        at android.os.Handler.dispatchMessage(Handler.java:
    102)

    But when I changed the Android.jar location from new Android SDK Manager (came with B4A 7.8) to old Android SDK Manager, the same code without any changes works fine.

    On new SDK Manager, I am getting another Exception:

    Code:
    java.lang.NullPointerException: Attempt to invoke virtual method 'void java.net.DatagramSocket.send(java.net.DatagramPacket)' on a null object reference
        at anywheresoftware.b4a.objects.SocketWrapper$UDPSocket$1.run(SocketWrapper.java:479)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:
    423)
        at java.util.concurrent.FutureTask.run(FutureTask.java:
    237)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:
    1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
    588)
        at java.lang.Thread.run(
    Thread.java:818)
    I guess I am missing something, which is required to be installed in the new SDK Manager.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the code that raises this error?
     
  3. Azam Memon

    Azam Memon Member Licensed User

    Code is attached, which is working with old SDK Manager GUI but not working with new SDK Manager (with B4A v7.8)
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    Works fine here (after I added a call to CheckForGooglePlayServices).

    You are probably using an old version of Google Play Services.

    Use the new sdk manager to install the latest versions and make sure that the IDE uses the new version: https://www.b4x.com/b4a.html
     
  5. Azam Memon

    Azam Memon Member Licensed User

    I am using Google Play Services 46 on both old and new GUI of SDK Managers, Google Play Services v46 is the latest one (see attachments)
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    Google Play Services component is not used anymore as Google stopped updating it a year ago.

    You should install all the recommended items and set the IDE to use the new SDK.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice