Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notes on building project with gradlew #179

Open
singseraphim opened this issue Dec 7, 2019 · 12 comments
Open

Notes on building project with gradlew #179

singseraphim opened this issue Dec 7, 2019 · 12 comments

Comments

@singseraphim
Copy link

singseraphim commented Dec 7, 2019

This project hasn't been updated since 2016, so it cannot be built with the latest version of gradle. There are some shenanigans that must be done. I am a very small programmer fish in this big scary ocean, but after a great deal of trial and error, I think I've found a way to make the project build properly on Windows.
Note: you'll want to just use "gradlew" in the command line instead of "./gradlew" in windows.
There are two things you need to do: Set the SDK to version 23, and set the buildtools to version 23.0.2.

  1. Install gradle on your computer, if you haven't already. (I am 60% sure this step was necessary- maybe it wasn't).

  2. In android studio, go to Tools -> SDK Manager. Check the box for Android 6.0(Marshmallow) and click "Ok". Now, if you were to run the gradlew command now, you would get an error like "cannot find BuildTools 23.0.2" or something like that. This is because the default Android Studio installation of SDK version 23 is 23.0.3, and the project wants 23.0.2. So we're going to fix that.

  3. On the command line, navigate to C:\Users[username]\AppData\Local\Android\Sdk\tools\bin. This is where the sdkmanager lives. It can install the build tools we need. Type 'sdkmanager "build-tools;23.0.2"' and hit enter. Make sure there's no whitespace anywhere within the quotes. Here's more info on sdkmanager: https://developer.android.com/studio/command-line/sdkmanager

  4. Go back to the location of the project. Run "gradlew", not "gradlew assemble". When I ran gradlew assemble it broke halfway through for reasons I couldn't decipher, but running "gradlew" will give you the .aar file in the location described in the setup.

Hopefully this will help! Godspeed!

PS To add the .aar file to your android project:
Move the .aar file into your android project directory (it can go anywhere)

  1. File -> New -> New Module -> Import .JAR/.AAR Package, click "Next"
  2. In "File Name:" put the location of the .aar file, click "Finish
  3. Go to File -> Project Structure -> Dependencies, click on "app" in the Module section
  4. Click the "+" sign above the dependencies and select "Module Dependency"
  5. Select the module you created
  6. Rebuild your project

PPS I'll just leave some notes on things I've had to fiddle with to make it work so far-

  • You need to add a dependency for "retrofit" in your project. Add the line "implementation ('com.squareup.retrofit:retrofit:1.9.0')" to your app build.gradle dependencies and rebuild.
  • You can see all of kaaes's source code if you look in that repository you cloned. It's super useful.

Edit
I've attached my .aar to my original post.
spotify-web-api-android-0.4.1.zip

@singseraphim singseraphim changed the title Notes on building with gradlew Notes on building project with gradlew Dec 7, 2019
@Finni123
Copy link

Finni123 commented May 5, 2020

I followed your steps closely but when typing "gradle" I get the following error while building:

> A problem occurred configuring project ':spotify-api'.
   > Could not resolve all dependencies for configuration ':spotify-api:_debugAndroidTestCompile'.
      > Could not find com.android.support.test:runner:0.2.
        Searched in the following locations:
            file:/C:/Users/xyz/.m2/repository/com/android/support/test/runner/0.2/runner-0.2.pom
            file:/C:/Users/xyz/.m2/repository/com/android/support/test/runner/0.2/runner-0.2.jar
            https://jcenter.bintray.com/com/android/support/test/runner/0.2/runner-0.2.pom
            https://jcenter.bintray.com/com/android/support/test/runner/0.2/runner-0.2.jar
            https://repo1.maven.org/maven2/com/android/support/test/runner/0.2/runner-0.2.pom
            https://repo1.maven.org/maven2/com/android/support/test/runner/0.2/runner-0.2.jar
        Required by:        
            com.spotify.android:spotify-api:0.4.1

EDIT:
This worked for me: the issue can be fixed by adding the following into your project build.gradle (I added it in buildscript repositories and subproject repositories)

        maven {
            url "https://maven.google.com"
        }

New Problem:

when I run "gradlew", it says "build successfull", but I can't find an aar file in build/output (there isn't even a folder called output) and when I run "gradlew assemble" I get this error half way through:

Execution failed for task ':spotify-api:compileReleaseJavaWithJavac'.
> Could not find tools.jar

@singseraphim
Copy link
Author

singseraphim commented May 5, 2020 via email

@Finni123
Copy link

Finni123 commented May 5, 2020

Hi Finni! Sorry you're having problems, this one is a tough nut to crack. It looks like com.android.support.test🏃 is an XML file that lives in the .idea/libraries directory of the project. I have no idea why it wouldn't be there, but I am happy to try to troubleshoot that with you if you'd like. Or I could send you my files. I could send you my compiled .aar so you can add it as a dependency to your project, or I could send you my whole project so you can see how I used it. What do you think?

Hi! I just updated my comment because I solved that problem but another one came up...
After spending so much time on this problem without any results, I am wondering, is this even worth it? Even if I get this library to build and run, it's only the android api 0.4, and currently 0.6 is the newest one. Is there really no other (up-to date, not dead) library for this?

@singseraphim
Copy link
Author

Oh man nice job solving that first problem!
What happens when you search your project file directory for all .aar files? Does anything show up?

Yeah it's kind of absolutely absurd that the best thing for this problem is something that hasn't been updated since 2016. The spotify dev team seems to have washed their hands of it. I spent a very long time looking at the other Android Spotify APIs trying to find a workaround but this is the only one that isn't fundamentally broken.
There was a point where I was thinking about setting up a web server that the app could talk to so I could handle API requests in javascript because it seems like there's way more support for that, but I ended up getting this one to work.

I think you are extremely close. If you can't find the .aar file, we can see about me sending you mine. Once you have the .aar dependency, the actual usage of the API is really smooth and easy to understand.

@Finni123
Copy link

Finni123 commented May 5, 2020

When I use "ext:.aar" to search for aar files in Windows Explorer the only file that shows up in the entire project folder is "spotify-auth-1.0.0-beta12.aar" in sample-search/libs, which is not what we want.

It would be super great if you could send me the .aar as I don't plan on changing anything in the code anyways, so I don't think I'd ever need to build this project again...

@singseraphim
Copy link
Author

Rad. Here you go! I really hope it works.

I also did a cursory look around and noticed that https://github.com/spotify/android-sdk has been updated recently and seems to have some good documentation. Maybe it wasn't there when I did this project, or maybe I decided it wouldn't work for me for reasons that have now been lost to time.

spotify-web-api-android-0.4.1.zip

@Finni123
Copy link

Finni123 commented May 5, 2020

Thank you so much! It's nice that the Android-API is being updated, but the readme.md says the following:

This library provides a way to obtain OAuth access tokens that can subsequently be used to play music or used in calls to the Spotify Web API.

To me, this sounds like they don't plan on expanding the Android-API functionality and instead make everyone use the Web-API.
(For me the problem isn't that the Android-API doesn't work but that it isn't nearly as powerfull as the Web-API [it can't even fetch playlists])

Anyways, thanks a lot!

@singseraphim
Copy link
Author

Spotify is a beautiful disaster in so many ways. And no problem, let me know how it goes!

@Finni123
Copy link

Finni123 commented May 6, 2020

So the module works now, I found out the hard way that retrofit 2 broke stuff, but adding this to module level build.gradle made it work:

    implementation 'com.squareup.retrofit:retrofit:1.9.0'
    implementation 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    implementation 'com.squareup.okhttp:okhttp:2.7.4'
    implementation 'com.squareup.okhttp:okhttp-urlconnection:2.7.4'

@singseraphim
Copy link
Author

singseraphim commented May 6, 2020 via email

@jiwaCh
Copy link

jiwaCh commented Feb 4, 2021

Does the method to addTracksToPlaylist still work? I ran the Test which was provided and it yields an error. Another methods seems to work fine for me as far as I know, expect this .

@singseraphim
Copy link
Author

Hmm I used that method in my project and it worked, but it's been about a year since I've touched it and I don't know if something has broken in the meantime. I hope you figure it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants