Android Question Autofill Services - adding it to your app

mfstuart

Active Member
Licensed User
Longtime User
I'm using the Autofill Service, defined in the manifest and also some code to define the view to be a Autofill type view.
When running the app, and touching into the view, the app immediately crashes with this error.
Can anyone explain why this happens and how to fix it?
B4X:
java.lang.RuntimeException: Unable to instantiate service com.mfstuart.autofill_demo.MyAutofillService: java.lang.ClassNotFoundException: Didn't find class "com.mfstuart.autofill_demo.MyAutofillService" on path: DexPathList[[zip file "/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/base.apk"],nativeLibraryDirectories=[/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/lib/arm, /system/lib, /system/vendor/lib]]
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3791)
    at android.app.ActivityThread.access$1500(ActivityThread.java:248)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1846)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7266)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mfstuart.autofill_demo.MyAutofillService" on path: DexPathList[[zip file "/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/base.apk"],nativeLibraryDirectories=[/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/lib/arm, /system/lib, /system/vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3786)
    ... 8 more
 

walterf25

Expert
Licensed User
Longtime User
I'm using the Autofill Service, defined in the manifest and also some code to define the view to be a Autofill type view.
When running the app, and touching into the view, the app immediately crashes with this error.
Can anyone explain why this happens and how to fix it?
B4X:
java.lang.RuntimeException: Unable to instantiate service com.mfstuart.autofill_demo.MyAutofillService: java.lang.ClassNotFoundException: Didn't find class "com.mfstuart.autofill_demo.MyAutofillService" on path: DexPathList[[zip file "/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/base.apk"],nativeLibraryDirectories=[/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/lib/arm, /system/lib, /system/vendor/lib]]
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3791)
    at android.app.ActivityThread.access$1500(ActivityThread.java:248)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1846)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7266)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mfstuart.autofill_demo.MyAutofillService" on path: DexPathList[[zip file "/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/base.apk"],nativeLibraryDirectories=[/data/app/com.mfstuart.autofill_demo-fmehVsDnOETFQrOSdcdFJw==/lib/arm, /system/lib, /system/vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3786)
    ... 8 more
Do you have a service named MyAutofillService in your project, by the looks of it seems the project is looking for that service and it does not find it.

Walter
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Do you have a service named MyAutofillService in your project, by the looks of it seems the project is looking for that service and it does not find it.

Walter
Is this what you are referring to?
I have this added to the end of the Manifest:
Manifest:
AddApplicationText(
<service
    android:name=".MyAutofillService"
    android:label="My Autofill Service"
    android:permission="android.permission.BIND_AUTOFILL_SERVICE">
    <intent-filter>
        <action android:name="android.service.autofill.AutofillService" />
    </intent-filter>
    <meta-data
        android:name="android.autofill"
        android:resource="@xml/service_configuration" />
</service>
)
On line 11 above, I have the service_configuration file sitting in the ...Objects/res/xml folder. It is set as Read Only.
service_configuration file contents:
<autofill-service
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:settingsActivity="com.mfstuart.autofill_demo.Main" />
The "com.mfstuart.autofill_demo.Main" in my understanding, is the Build Configuration/Package name and is also a reference to the Activity in which the Autofill service is used. I could be wrong.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Is this what you are referring to?
I have this added to the end of the Manifest:
Manifest:
AddApplicationText(
<service
    android:name=".MyAutofillService"
    android:label="My Autofill Service"
    android:permission="android.permission.BIND_AUTOFILL_SERVICE">
    <intent-filter>
        <action android:name="android.service.autofill.AutofillService" />
    </intent-filter>
    <meta-data
        android:name="android.autofill"
        android:resource="@xml/service_configuration" />
</service>
)
On line 11 above, I have the service_configuration file sitting in the ...Objects/res/xml folder. It is set as Read Only.
service_configuration file contents:
<autofill-service
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:settingsActivity="com.mfstuart.autofill_demo.Main" />
The "com.mfstuart.autofill_demo.Main" in my understanding, is the Build Configuration/Package name and is also a reference to the Activity in which the Autofill service is used. I could be wrong.
I'm referring to a service module.

Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
android:name=".MyAutofillService
So in your Manifest file you added this, that should be the name of the Service Module, you can name it whatever you want as long as it matches the name you add in the Manifest file.

I suggest you start with the basics, seems like you're trying to create something that is far more advanced than what you have learned so far.

Walter
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
So in your Manifest file you added this, that should be the name of the Service Module, you can name it whatever you want as long as it matches the name you add in the Manifest file.

I suggest you start with the basics, seems like you're trying to create something that is far more advanced than what you have learned so far.

Walter
Thanx for the heads up on the naming.
Yep, you are exactly right. I know what I want to do, but I don't know how to get there.
There are plenty of java code on the Android Developer website, but it's putting that into the B4A environment. For someone who is a Android Studio user, there are heaps of code and examples out there that you can just copy into your project. Easy-Peasy, right?
For us B4A developers, there's really not that available.
So what do you do? It's a struggle. I wish there was more Erel examples on his website and/or forum for such things. It would benefit the community a whole lot.
I try to copy up projects or bits of code that I've learned over time that helps others. It seems that's the only extended examples out there. Especially compared to what Android Developer website has. Yes, I know, they have more people to do this compared to Erel is only one man.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Thanx for the heads up on the naming.
Yep, you are exactly right. I know what I want to do, but I don't know how to get there.
There are plenty of java code on the Android Developer website, but it's putting that into the B4A environment. For someone who is a Android Studio user, there are heaps of code and examples out there that you can just copy into your project. Easy-Peasy, right?
For us B4A developers, there's really not that available.
So what do you do? It's a struggle. I wish there was more Erel examples on his website and/or forum for such things. It would benefit the community a whole lot.
I try to copy up projects or bits of code that I've learned over time that helps others. It seems that's the only extended examples out there. Especially compared to what Android Developer website has. Yes, I know, they have more people to do this compared to Erel is only one man.
post your project and we can help, otherwise we are just going by what you are describing here, or if you can't share your project, you can create a small example of what you are trying to accomplish and we can take a look.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Here's what I have so far with the attached project (zipped).
The app does run, but when you touch into the username or password views, it crashes immediately.
 

Attachments

  • Autofill_Service.zip
    10.5 KB · Views: 110
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Here's what I have so far with the attached project (zipped).
The app does run, but when you touch into the username or password views, it crashes immediately.
Here's a working example
 

Attachments

  • AutoFillExample.zip
    22 KB · Views: 121
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Here's a working example
I've been working with your example. With the added Service module, the app does not crash when touching into any of the 3 views. THANK YOU!
(I've never worked with a Service module before, had no need to as the apps I build are database oriented, either with Web Services and/or local SQLite DB)

I'm now trying to get the app recognized on my phone for Autofill Services in the phone Settings. I had it working before but now it is not.
I see what you did to the Manifest. With your changes the app is not recognized in the Settings - Autofill selection of the default app for Autofill Services.

I had copied the Android Developer manifest entry from Build autofill services, into B4A's manifest, into a "AddApplicationText" section. But this did not work with my demo app this time around. I also tried it in your example, but also did not work. Work, I mean, that it should be recognized by the Android OS to be a selectable app in the Settings - Autofill Services setup.

The web page also mentions about the service_configuration file contents:
"The service_configuration resource in the previous example specifies an activity that allows users to configure the service." Refer to my post #3 to see the contents.
This part of the entry: android:settingsActivity="com.example.android.SettingsActivity - refers to an activity in the app? Obviuosly the Package name is part of it and the SettingsActivity is also referenced. Is this an actual Activity name or is it just part of the default statement for the configuration?
The web page really doesn't explain it that well.
I've tried both my Activity name and "SettingsActivity". Both don't work to have the phone recognize the app that will be the default for Autofill Services.


Any suggestions or incite are welcome.

Thanx,
Mark
 
Last edited:
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
I now have my app being recognized by the Android OS in the Settings - Autofill Services to be able to select my app as the default for Autofill.
Now I will continue with adding the Sub routines that recognize the 2 views (Username and Password) as the Autofill values.

This is the Autofill Service entry I added to the end of the B4A Manifest:
B4X:
'Autofill Service
AddApplicationText(
<service
    android:name=".AutofillService"
    android:label="Your app name here"
    android:permission="android.permission.BIND_AUTOFILL_SERVICE">
    <intent-filter>
        <action android:name="android.service.autofill.AutofillService" />
    </intent-filter>
    <meta-data
        android:name="android.autofill"
        android:resource="@xml/service_configuration" />
</service>
)
It includes:
1) B4A Service module name: android:name=".AutofillService" (you will need to add a Service Module to your app. Name it exactly the same as this entry (without the fullstop/period character. In this example: AutofillService) What goes into this Service Module I'm still learning.
2) Android Settings - Autofill Services title: android:label="Your app name here"
3) the permission needed for your app to use the Autofill Service: android:permission="android.permission.BIND_AUTOFILL_SERVICE"
Further down is the reference to the service_configuration file. The file resides in the /Objects/res/xml folder. Set the file to Read-only.
I have seen the app create this file and its contents when it runs, and its contents do not need to be changed. If need be, create the file and its contents.

More to come...
 
Last edited:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I now have my app being recognized by the Android OS in the Settings - Autofill Services to be able to select my app as the default for Autofill.
Now I will continue with adding the Sub routines that recognize the 2 views (Username and Password) as the Autofill values.

This is the Autofill Service entry I added to the end of the B4A Manifest:
B4X:
'Autofill Service
AddApplicationText(
<service
    android:name=".AutofillService"
    android:label="Your app name here"
    android:permission="android.permission.BIND_AUTOFILL_SERVICE">
    <intent-filter>
        <action android:name="android.service.autofill.AutofillService" />
    </intent-filter>
    <meta-data
        android:name="android.autofill"
        android:resource="@xml/service_configuration" />
</service>
)
It includes:
1) B4A Service module name: android:name=".AutofillService" (you will need to add a Service Module to your app. Name it exactly the same as this entry (without the fullstop/period character. In this example: AutofillService) What goes into this Service Module I'm still learning.
2) Android Settings - Autofill Services title: android:label="Your app name here"
3) the permission needed for your app to use the Autofill Service: android:permission="android.permission.BIND_AUTOFILL_SERVICE"
Further down is the reference to the service_configuration file. The file resides in the /Objects/res/xml folder. Set the file to Read-only.
I have seen the app create this file and its contents when it runs, and its contents do not need to be changed. If need be, create the file and its contents.

More to come...
This will only work if you set the target SDK to 28, if you try to set it to anything above 28 it will not work.

Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Hi Walter,
Where did you find that info, or did you try setting the different target SDK's yourself and test it?
I tried with with targetSDK of 31 and I get an error.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Yeah, that's what I was getting.
In my main app, not the demo app I've uploaded here, it is crashing when touching into the views.
I will down grade the target SDK to 28 and see what happens.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Yeah, that's what I was getting.
In my main app, not the demo app I've uploaded here, it is crashing when touching into the views.
I will down grade the target SDK to 28 and see what happens.
I have a working example, I will try to upload it later today.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
In my main app, I had the Service module named like this "AutofillService", and it is crashing like I said.
I changed the Service module name to all lower case and the B4A Manifest to lower case as well, and it is not crashing when I touch into the not important and the 2 views that are Username and Password.

Was there an original reason you named the Service module in your example to all lower case? In your Manifest you have the android:name=AutofillServce as this.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
So far, this is what is in my Service module, the default subs:
autofillservice - Service module content::
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals

End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0
Top