SDL2.0.8 with Android Studio 3.0.1


#1

I’m trying to build the included android-project within SDL-2.0.8-11687. I get the following error:

W:\SDL-2.0.8-11687\android-project\app\src\main\java\org\libsdl\app\SDLActivity.java:220: error: cannot find symbol
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                ^
  symbol:   variable SYSTEM_UI_FLAG_IMMERSIVE_STICKY
  location: class View
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

I have tried changing the Android API versions in my AndroidManifest.xml to:

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />

…but I still cannot get it to build.

I have uploaded my Android Studio project here

Would somebody please help - it would be very useful to have a working SDL project so any Android Studio user can just pick it up and start using it.


#2

I would suggest to make a Github repo.

Greetings,


#3

change the compileSdkVersion to 19 in android-project/app/build.gradle

see https://bugzilla.libsdl.org/show_bug.cgi?id=3937


#4

@Sylvain_Becker have you looked at my suggested patch on that issue? Any comments?


#5

Yes, looks like a good idea !


#6

Sorry people - I would have uploaded a GIT rep and tried out other suggestions but Android Studio is being a pain. I have tried running this project on 3 different (Windows) machines and I get different results everywhere. At home I’m getting lots of NDK errors now such as:

W:\Android\sdk\ndk-bundle\build\core\setup-app.mk
Error:(80, 0) Android NDK: Application targets deprecated ABI(s): armeabi    

I’ll need to completely remove and re-install Android Studio once again before I can try anything more with this. I’m glad I don’t pay per Gb anymore for my Internet usage!


#7

The latest android studio deprecated armeabi and mips builds, but they are still compiled by default. It says error but really it’s just a warning and you can ignore it if you want. I.e. it should not cause the build to fail in my experience.

I’ve reported the “warning shown as an error” issue to google (https://issuetracker.google.com/issues/69516963) but they haven’t responded yet.


#8

Thanks. Unfortunately it is definitely stopping on the following error though:

W:\Android\sdk\ndk-bundle\build\core\build-binary.mk
Error:(693) Android NDK: Module main depends on undefined modules: SDL2    
Error:(706) *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.

I’m just googling now to figure out how to set APP_ALLOW_MISSING_DEPS…

And the fact that I don’t have a cpp or jni folder in the Android Studio project doesn’t help so I can’t easily go into my Android.mk/Application.mk from there. The whole project is a mess on the current machine I’m using - and that was after reinstalling Android Studio and NDK.


#9

Are you still trying to build the SDL android example project? There should be a app/jni dir where you need to copy (or symlink) sdl into.


#10

Yes I was just trying to build it as-is. Surely we still don’t need to go through that complication of creating symbolic links to SDL etc again? I went through that on the Mac when building using ant etc from the command line and that was really painful.

With Android Studio there should be a project already provided so people can just build it and ‘go’ without following long instructions. That’s what I would like to see in an ideal world. :slight_smile:


#11

Yes. I agree completely. I’ve actually made something like that, but I ran into some issues with gradle and android studio so it’s not 100% finished. And I haven’t even tried getting it into SDL yet


#12

I’m just wondering whether to give LazyFoo’s tutorial a go now… I guess I’m more frustrated with the fact that I’m struggling to continue with my own project that uses ant etc. The big barrier I hit with that project was that I couldn’t figure out how to include various GoogleSign-in packages… and I struggle on the Mac… I thought installing Android Studio on Windows would be my silver bullet. :slight_smile: Oh well I may as well give it a go. Given that the tutorial was for AS 2.3.3 I just hope it works with AS3.0.1…


#13

OK, I’m now trying to follow Lazy Foo’s tutorial

  1. I had to change Change C:\androidprojects\SDL\gradle\wrapper\gradle-wrapper.properties to use gradle-4.1-all.zip
  2. I downloaded Android SDK 16

Try to Make the project and I get this:

C:\androidprojects\SDL\app\src\main\java\org\libsdl\app\SDLActivity.java:7: error: cannot find symbol
import java.util.Objects;

Gradle Console also shows:
file or directory 'C:\androidprojects\SDL\app\src\debug\java', not found

Debug console output has this line:
15:19:12.229 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -source 1.6 -target 1.6 -d C:\androidprojects\SDL\app\build\intermediates\classes\debug -encoding UTF-8 -bootclasspath C:\androidsdk\platforms\android-16\android.jar -g -sourcepath -proc:none -XDuseUnsharedTable=true -classpath -s C:\androidprojects\SDL\app\build\generated\source\apt\debug C:\androidprojects\SDL\app\src\main\java\org\libsdl\app\SDL.java C:\androidprojects\SDL\app\src\main\java\org\libsdl\app\SDLActivity.java C:\androidprojects\SDL\app\src\main\java\org\libsdl\app\SDLAudioManager.java C:\androidprojects\SDL\app\src\main\java\org\libsdl\app\SDLControllerManager.java C:\androidprojects\SDL\app\build\generated\source\r\debug\org\libsdl\app\R.java C:\androidprojects\SDL\app\build\generated\source\buildConfig\debug\org\libsdl\app\BuildConfig.java

Just read a StackOverflow post that claims my Java version must be wrong. The java.utils.Objects were only introduced with Java 7 so it says, but I should have Java 8. If I run from a command prompt:

C:\Users\Paul>java -version
java version "1.8.0_91"

However, Android Studio was using the embedded Java version. So… I tried changing it as follows:

Change Java version File->Project Structure - stop using internal JDK:
C:\Program Files\Java\jdk1.8.0_91

Same problem.

Tried “File->Invalid Caches/Restart

Same problem.

Help please? I’m keeping notes as I go so I could write my own AS3.0.1/SDL2.0.7 tutorial if need be.


#14

That’s probably an issue with the 2.0.7 SDL. See SDL 2.0.7 Error Andriod Studio

So try a newer snapshot or the latest sources. There have been quite a lot of Android build braking changes lately so your mileage may vary.

Also if you update the gradle wrapper you probably need to change other things in the build.gradle also. See https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

In practice you need to add the google repositories and update the plugin version to the build.gradle in the root folder and change “compile” -> “implementation” in the dependencies in the app/build.gradle file.


#15

Thanks. That link you said was consistent with what I had. Unfortunately the 2.0.8-11724 snapshot has rendered LazyFoo’s tutorial completely out of date. Importing the project from the 2.0.8 snapshot doesn’t even ask me where I’d like the destination project to be so I had to start guessing what to do from that point.

The jni folder seems to be expected as app\jni folder now instead of app\src\main\jni. The “Link C++ Project with Gradle” option doesn’t appear in Android Studio’s context menu anymore and all I can see in the Project window is an empty “cpp” folder.

I added the SDL2 symbolic link under the app\jni folder and I get these errors:

C:\androidsdk\ndk-bundle\build\core\build-binary.mk
Error:(692, 0) Android NDK: Module main depends on undefined modules: SDL2    
Error:(705, 0) *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.

I am completely stuck now.

I’m sorry that I didn’t understand the last two sentences in your reply - if I’ve started a new project for 2.0.8-11724 then I’m guessing I would be using whatever version of Gradle/wrapper was defined in the snapshot.


#16

Sounds like the linking is not done correctly. If you are on windows you can use something like:

mklink /D SDL c:\libs\SDL

Run that in the app\jni dir but change the last path to be an absolute path to you SDL. Also you need to do that from an admin command prompt.

After that it should look something like this:
image
If you linked to the correct place, entering the SDL dir you will see the root of the sdl sources

I haven’t looked at LazyFoo, but this is the simplest way to get the current version to work:

  • Use a somewhat new snapshot or sources from version control
  • Link your SDL directory to SDL/android-project/app/jni
  • Add your c source code to SDL/android-project/app/jni/src and modify the Android.mk there accordingly
  • Done. Now you can build from the command line by running gradlew.bat assemble or open android studio and run from there. If Android studio asks you to upgrade the project to newest plugin/gradle don’t do it (yet at least).

I just tried this with the latest sources and didn’t do anything else and it worked.

Later you can modify the app name/package etc. or update to newer gradle, but try to get this to build and run first.


#17

Thanks for that. I think the last problem may have been the name of the symbolic link. LazyFoo’s tutorial assumes there is a link to SDL2. Your suggestion showed SDL (without the ‘2’).

I removed the SDL2 link, added SDL2 as below:

 Directory of C:\androidprojects\SDL\app\jni

24/10/2017  10:01 a.m.                37 Android.mk
07/12/2017  12:22 p.m.               212 Application.mk
07/12/2017  12:31 p.m.    <SYMLINKD>     SDL [C:\androidlib\SDL-2.0.8-11724]
07/12/2017  12:20 p.m.    <SYMLINKD>     SDL2 [C:\androidlib\SDL-2.0.8-11724]
07/12/2017  12:21 p.m.    <DIR>          src

C:\androidprojects\SDL\app\jni>del SDL2

This appears to have moved forward somewhat. It started trying to build the “52_hello_mobile.cpp” source file. Unfortunately that failed due to not being able to link with the SDL library.

[armeabi] SharedLibrary  : libmain.so
C:/androidprojects/SDL/app/jni/src/52_hello_mobile.cpp:248: error: undefined reference to 'SDL_DestroyTexture'

image

I still don’t know why the cpp folder is showing empty though. Its not very helpful that I can’t see the Android.mk and .cpp files. No doubt this relates to some gradle version or plugin. I thought the days of the ‘experimental plugin’ were gone.

I also clicked on “Remind me Tomorrow” for the below dialog:

image

What my problem be now? Should I have created a seperate project to build the SDL2 library itself?

My test app’s Android.mk contains:

LOCAL_SHARED_LIBRARIES := SDL2

…but I have no idea where that would be located.


#18

Your listing still shows the SDL2 symlink. Make sure have deleted that because the project is setup so that it’s trying to build every subfolder in the app/jni dir.

Android Studio seems to not be able to sync the project because the build is failing. It will probably show the file once the build doesn’t fail anymore.

Maybe try deleting build and .externalNativeBuild from both the android-project and app dirs to clean any old stuff and try to rebuild.


#19

btw. the SDL2 library is defined in the SDL dir you just symlinked. Like I said the project is setup so that it searches for Android.mk in each subdir. You can look at app/jni/SDL/Android.mk. It defines all the stuff SDL is building


#20

Yes I removed the SDL2 symbolic link:

Directory of C:\androidprojects\SDL\app\jni

07/12/2017  12:51 p.m.    <DIR>          .
07/12/2017  12:51 p.m.    <DIR>          ..
24/10/2017  10:01 a.m.                37 Android.mk
07/12/2017  12:22 p.m.               212 Application.mk
07/12/2017  12:31 p.m.    <SYMLINKD>     SDL [C:\androidlib\SDL-2.0.8-11724]
07/12/2017  12:21 p.m.    <DIR>          src