Android Question SOLVED HTTP fails after simple manifest update to target 28?

Unobtainius

Active Member
Licensed User
Longtime User
I'm not even sure where to start? I got the warning suggesting to update the manifest to targetSdkVersion="28"
So I did. Now a project that worked perfectly with it set to 27, fails when I set it to 28?
Please ignore &deviceid=unknown in my call, I would normally get a JSON error message back with device unknown, but in this instance it just crashes
All I have to do to get it all working as expected is to set the manifest back to 27.
I would like to use the latest one, so if someone could help me overcome this issue, it would make my day


** Activity (main) Resume **
Class anywheresoftware.b4a.B4AThreadPool failed lock verification and will run slower.
EGLNativeWindowType 0xe79f3008 disconnect failed
eglDestroySurface = 0xcfe56000, 0xe79f3000
Relayout returned: old=[120,837][1079,1011] new=[120,837][1079,1011] result=0x5 surface={false 0} changed=true
Relayout returned: old=[0,0][1200,1920] new=[0,0][1200,1920] result=0x1 surface={true 3986130944} changed=false
MSG_WINDOW_FOCUS_CHANGED 1 1
prepareNavigationBarInfo() DecorView@e8be930[main]
getNavigationBarColor() -855310
MSG_WINDOW_FOCUS_CHANGED 0 1
Web. OK
?ACTION=SELECT&fields=`stocklocation`.`idStockLocation`, `stocklocation`.`LocationDescription` &table=`stocklocation`&where=`stocklocation`.`idStockLocation` <> 0&order=`stocklocation`.`LocationDescription` &deviceid=unknown
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/methods/HttpGet;
at anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper.InitializeGet(HttpClientWrapper.java:342)
at anywheresoftware.b4a.samples.httputils2.httpjob._download2(httpjob.java:109)
at atec.marcus.asmstocktaker.clsdb$ResumableSub_GetRecordset.resume(clsdb.java:1367)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1761)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7100)
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:964)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.methods.HttpGet" on path: DexPathList[[zip file "/data/app/atec.marcus.asmstocktaker-gAvan0iRrT2MAaQGGyeBJw==/base.apk"],nativeLibraryDirectories=[/data/app/atec.marcus.asmstocktaker-gAvan0iRrT2MAaQGGyeBJw==/lib/arm, /system/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)
... 23 more
 

Unobtainius

Active Member
Licensed User
Longtime User
after the manifest as below, the error still remains

AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
SetApplicationAttribute(android:networkSecurityConfig, @xml/network_security_config)
CreateResource(xml, network_security_config.xml,
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
)

'End of default text.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Are you pointing to Android.jar of Android 28 in B4A Configure Path?
 
Upvote 0

Unobtainius

Active Member
Licensed User
Longtime User
Ok thanks, I will give it a go tomorrow morning
 
Upvote 0

Unobtainius

Active Member
Licensed User
Longtime User
Works like a charm. Thank you very much and, sorry for bothering you when the library window clearly states HTTPutils has been depreciated
Sometimes one cant see the forest for the trees
Thanks again
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
more changes to your manifest; you have to add this:
SetApplicationAttribute(android:usesCleartextTraffic, "true")
 
Upvote 0

Alexander1981

Member
Licensed User
My manifest
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

SetApplicationAttribute(android:networkSecurityConfig, @xml/network_security_config)
CreateResource(xml, network_security_config.xml,
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
)
SetApplicationAttribute (android: usesCleartextTraffic, "true")



ERROR :
AndroidManifest.xml:22: error: Error parsing XML: not well-formed (invalid token)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
check this link. it's not completelyl applicable, but about half way down it mentions 2 things:
1) networkSecurityConfig
2) a slightly different manifest change relating to "cleartext"

it also explains what's up with okhttputils2 and sdk 28 and a change google made that requires manually allowing "cleartext" over http.
the guy who was answering the problem is pretty high up the food chain here, and his reaction to "networkSecurityConfig" was the same as mine: where does it come from? if he doesn't know what it is, i certainly don't.

a little further down, a slightly different manifest addition is used regarding cleartext. you might want to try that one instead.

the reason you can't connect over http (versus https) with okhttputils and sdk 28 is because google basically turned it off. you have to expressly override it. i check one of my apps that is sdk 28 and has to use http. i added:
B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)
to my manifest using this version. try this one instead.

sorry it's not getting better.
 
Upvote 0

Alexander1981

Member
Licensed User
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)

SetApplicationAttribute(android:networkSecurityConfig, @xml/network_security_config)
CreateResource(xml, network_security_config.xml,
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>

)



____________________________________________________________________________________________________________________________________________________________________________
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
CreateResourceFromFile(Macro, Core.NetworkClearText)

I´ve
B4A 9.80
Android 28
jdk1.8.0

CODE:
PageServer = " http://example.com?field=valor "
Dim js como HttpJob
js.Initialize ("", Me)
js.Download (PageServer)
Esperar (js) JobDone (js como HttpJob)


Nothing stays the same, it does not vote any error, but it does nothing
I need urgent help please
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the code, as you show it, is not meant to do anything but download the page. if you want to see what was downloaded, you need:

B4X:
dim PageServer as string = "[URL='http://example.com/?field=valor'][B]http://example.com?field=valor[/B][/URL]"
Dim js como HttpJob
js.Initialize ("", Me)
js.Download (PageServer)
wait for (js) JobDone (js as HttpJob)
if js.Success then                
   dim text as string = js.getString
  log ("GOT: " & text)
else                          
   log(lastexception.message)
End If
j.Release


also, it sounds like the issues relating to cleartext have been resolved, yes?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i don't care what the url is. the code you showed only downloads. it does not show the information. you need to add lines 6 through 12 as i wrote previously.
 
Upvote 0

Alexander1981

Member
Licensed User
B4X:
Try
        Dim PageServer As String 
        PageServer = "http://xxxe/xxx/datacsjar.php"

        'inserta todas las Filas
        Dim js As HttpJob
        js.Initialize("", Me)
        'js.Download(PageServer)
                
        js.download2(PageServer, Array As String ("tabla","sede"))
        'Wait For JobDone(js As HttpJob)
[B]        Wait For (js) JobDone(js As HttpJob)  from here goes another event [/B]
        
        If js.Success Then
            Dim res As String
            res = js.GetString
            Dim parser As JSONParser
            parser.Initialize(res)
            If res <> False Then
                Dim Tabla As List
                Tabla = parser.NextArray
                Dim Fila As Map
                Dim codigo,descripcion As String
                If Tabla.size=0 Then
                    Msgbox("ID no encontrado","Aviso")
                    Return
                End If
                
                For i=0 To Tabla.size-1
                    Fila =  Tabla.Get(i)
                    codigo = Fila.Get("c_sede")
                    descripcion = Fila.Get("s_sede")
                    Lvt_sede.AddTwoLines(codigo,descripcion)
                
                    
                    spn_sede.Add(descripcion)
                '    spn_sede.TextSize=15
                    
                    
                Next
                
            End If
            
            End If
    Catch
        Log(LastException)
    End Try
    'Log(js.GetString)
 
Upvote 0
Top