There is a problem with Spotify app:
"Spotify connect" is not displayed as "available device" if hosts file contains blank lines.

Blank lines are valid in hostfiles on all systems (any *BSD, *UX, even on DOS and WIN). So it's a problem of Spotify app to be reported there.
@guest4711 no it's not fault from the Spotify App as it works if you disable Adaway!
@spafm simply whitelist: spclient.wg.spotify.com
Whitelisting spclient.wg.spotify.com worked for me too. Thanks!
Update: Whitelisting spclient.wg.spotify.com stopped working for me.
Same issue, workaround is not working
Spotify connect currently works for me by whitelisting the following:
*spotify.com*
104.199.64.74
104.199.65.25
239.255.255.250
35.186.244.62
224.0.0.251
Somehow not working for me, seems the wildcard *spotify.com* is not catching all.
I see that the client connects to: gew1-accesspoint-b-fl0z.ap.spotify.com
Where the bold characters are randomly generated it seems
I have the same problem, whitelisting all of the previous IPs and spotify.com does not currently work.
I am having the same issue and none of the whitelisting mentioned works.
Some other information that may be helpful.
My laptop running spotify always appears in the spotify app in my phone when it is running, but my sonos speakers normally do not
If I use spotify connect from my laptop to start playing spotify through one of my sonos speakers, then the sonos speaker I am playing on does appear in the spotify app on my phone
Disabling adaway makes all sonos speakers appear in the spotify app on my phone
Latest beta fixes this problem
Is that spotify, sonos or adaway beta that fixes the problem?
Adaway beta client, shared on xda forum
I tried version 4.0.2 from the xda forum and still had the same issue.
However I have managed to come up with a workaround to get it to work. The problem is in the way the spotify app resolves localhost, so although this works, the reason it is not working is spotify and not a problem with adaway.
To get it to work, I download and apply latest hosts in adaway. Then I opened the hosts file and at the top, you will see 2 entries for localhost - one with an ipv4 address and one with an ipv6 address
127.0.0.1 localhost
::1 localhost
I changed one of the entries to have a different name and saved it - eg
127.0.0.1 localhost
::1 localhost-ipv6
Then spotify app saw my sonos speakers as spotify connect devices.
The downside of this is that it needs to be done each time new files are downloaded in adaway
Maybe this Issue should be linked here? https://github.com/AdAway/AdAway/wiki/ProblematicApps
@antxxxx Thank you so much, your solution solved it for me!
@antxxx Thanks! This was driving me crazy!
Any chance this could be fixed within adaway?
@kalpik you forgot one x (@antxxxx), wrong antxxx :p
I having the same issue but fixed it. Thanks to @antxxxx
@antxxxx
How did you edit the file? Any text editor app I use always crashes due to to the sheer number of entries in the file. I tried using sed too but that didn't work
The localhost entries are standard on virtually all computers. They are NOT blocking rules! These are legitimate entries.
At least the IPv4 version (127.0.0.1 localhost) should be kept. Otherwise all kind of apps and system features might break. If you keep the IPv4 version it should be quite safe to delete the IPv6 entry (::1 localhost or similar) completely, though. There is no value in changing it to another host name. It'll just unnecessarily block the name you changed it to.
@Vankog agree - its not a problem with adaway and should not be fixed here - the problem is how spotify resolves localhost.
@anzetal - I think I ended up copying the file to my laptop and editing it on there, which I know is not a good solution. I use a custom tasker task now to download the adaway blocking host files and have a toggle to quickly disable or enable using it, and I just disable host file blocking when I want to use spotify and sonos
Will adding redirect rule ::1 localhost-ipv6 work, or should we delete/modify ::1 localhost?
short answer: delete ::1 localhost
long answers:
::1 localhost to ::1 localhost-ipv6 effectively is the same as doing both of the above.Thanks for your explaining~
Just to make sure: if spotify (connect) and adaway is active right now the only solution is the workaround as described earlier?
Summarizing the above and adding my own findings:
The following steps currently seem to mostly solve the issue (which is definitely a bug in Spotify, not in Adaway).
EDIT: fixed it
For those having problems editing on PC and copying the changed hosts file via adb or rooted file managers, you can use TWRP file manager to copy the modifed hosts file
Use the whitelist feature of AdAway. Add spclient.wg.spotify.com to the whitelist.
On November 18, 2018 1:31:55 PM GMT+01:00, rahul-sundaresan notifications@github.com wrote:
@github-ronk how do you edit the file? Most android editors crash or
throw up permission errors even with su access while modifying
/system/etc/hosts--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
https://github.com/AdAway/AdAway/issues/1009#issuecomment-439689406
@rahul-sundaresan - Since I like to apply ad-away hosts frequently, I use a shell script to do the modification automatically on the phone itself in a shell window.
(this is from memory - if you want to use it, check it first, and since it must be run as root, I'm adding the expected disclaimer - use at your own risk. This script may: not work as intended, and/or brick your phone, and/or annihilate the whole universe.
function exit5() {
echo $* - exiting in 5 seconds
sleep 5
exit
}
f=/system/etc/hosts
tmpf=/sdcard/myfolder/tmphosts$$.txt
[ -r $f ] || exit5 "cannot read $f"
touch $tmpf || exit5 "cannot create $tmpf"
wcoutput="$(wc -l $f)"
read n f <<<"$wcoutput"
[ "$n" -ge 2 ] || exit5 "bad number of lines $n in $f"
[ -s $tmpf ] && exit5 "non-zero size of $tmpf"
let newn=$((n - 1))
(head -"$newn" $f | grep -v '::1' | grep . ; echo -n $(tail -1 $f) ) > $tmpf
wc -l $f $tmpf
echo -n "If looks OK, hit enter to continue. Otherwise - ^C to abort: "
read && {
cat $tmpf > $f
echo -n DONE...
}
rm -f $tmpf
echo bye
In case anyone wants to understand what is going on: Spotify (in liborbit-jni-spotify.so) looks up the hostname with gethostname, then will do a getaddrinfo(hostname, NULL, ...) and then checks if more than one address was returned. If that is the case, it will do setsockopt(socket, SOL_IP, IP_MULTICAST_IF, addr) for each found IPv4-Address.
On my device, gethostname returns localhost, causing getaddrinfo to return [127.0.0.1, ::1]. As this list contains more than one entry, spotify will bind the socket with IP_MULTICAST_IF to 127.0.0.1 and therefore send out the mDNS broadcast over the lo interface. With the fix, IP_MULTICAST_IF is never set as getaddrinfo returns just one address, and the broadcast will go out through the proper interface.
In case anyone wants to understand ...
Very illuminating, thanks!
On my device, gethostname returns localhost, causing getaddrinfo to return [127.0.0.1, ::1]. As this list contains more than one entry, spotify will bind the socket with IP_MULTICAST_IF to 127.0.0.1 and therefore send out the mDNS broadcast over the lo interface. With the fix, IP_MULTICAST_IF is never set as getaddrinfo returns just one address, and the broadcast will go out through the proper interface.
This actually sounds like a fully fledged Spotify bug. Might be worth reporting this.
127.0.0.1 localhost
::1 localhost
are totally legitimate entries that are globally established. This has nothing to do with AdAway besides the fact that it writes the two entries to the host file.
Spotify should behave accordingly.
If anyone is interested, I have compiled a patched version of AdAway, that implements this workaround for Spotify (omits the line ::1 localhost). See https://github.com/c64bob/AdAway/releases/tag/v4.1.0
Brilliant! Works perfectly :)
I cannot install the patched version on my oneplus 5t with android 9.
only error message from the packet installer says "app was not installed"
I already tried to first uninstall the original Adaway and then to install the patched one, but the error message stays the same
what could be the problem here?
Installed fine on my 5t but only after removing/uninstalling original adaway version
i don't know what i did wrong the last time i tried that, but now it works as you described.....so my problem is solved
Most helpful comment
I tried version 4.0.2 from the xda forum and still had the same issue.
However I have managed to come up with a workaround to get it to work. The problem is in the way the spotify app resolves localhost, so although this works, the reason it is not working is spotify and not a problem with adaway.
To get it to work, I download and apply latest hosts in adaway. Then I opened the hosts file and at the top, you will see 2 entries for localhost - one with an ipv4 address and one with an ipv6 address
I changed one of the entries to have a different name and saved it - eg
Then spotify app saw my sonos speakers as spotify connect devices.
The downside of this is that it needs to be done each time new files are downloaded in adaway