qmake fine tuning
-
Hi All!
I'm trying to build a java jar library, required for android's part of my project. Java lib employs native code, so I need a strict sequence of build process:
- compile java sources (e.g javac ..... with *.class as output)
- regenerate java->c native methods headers (e.g. javah .... with java_with_its_strange_naming_convention*.h as outcome)
- compile native code itself (arm's g++ .... libNativeCodeIsHere.so)
- assemble all the parts into .jar archive.
To tell the truth, I tried to implement these tasks using Android Studio and Intellij Idea, but failed to, as soon as something called "gradle" is beyond my understanding skills. Again, my 10 y.o. notebook is something being disregarded by fat java cats, keeping development tools to eat all "leading edge performance". But enough whining. Old good QtCreator has got this job.
And here is the quiz: if I employ qmake's "app" TEMPLATE, being configured to build for Android, it produces .apk, that is not what I need. But when I switch to "lib" template, I can't teach qmake the correct sequence of tasks. I tried to utilize QMAKE_EXTRA_TARGETS, but it just refuses to embed appointed targets into build sequence. I see, it adds .buildJavaClasses: target in Makefile, but not more - it doesn't add this target in mainline buld sequence.
So far my .pro looks like this:
#------------------------------------------------- # # Project created by QtCreator 2018-04-02T04:41:55 # #------------------------------------------------- QT -= core gui TARGET = andy TEMPLATE = lib #CONFIG += plugin DEFINES += ANDROID_ANDY_LIB_LIBRARY # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. #DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ andy_native.cpp HEADERS += \ com_andy_AndyActivity.h \ andy_native.h android { firsttarget.target = firsttarget firsttarget.commands += javac -cp /home/user/Android/platforms/android-26/android.jar:/home/user/Unity-2018.1.0b8/Editor/Data/PlaybackEngines/AndroidPlayer/Variations/mono/Release/Classes/classes.jar -sourcepath java/src java/src/com/andy/ AndyActivity.java -d java/classes ....... lasttarget.taret = lasttarget lasttarget.commands = jar cvfM andy.jar -C java/classes . QMAKE_EXTRA_TARGETS = firsttarget #POST_TARGETDEPS = lasttarget } DISTFILES += \ java/src/com/andy/AndyActivity.java
Any clues how to beat it?
-
@Stanislav-Silnicki long story short: i did it.
- write correct targets interdependency in .pro:
#------------------------------------------------- # # Project created by QtCreator 2018-04-02T04:41:55 # #------------------------------------------------- QT -= core gui TARGET = andy TEMPLATE = lib DEFINES += ANDROID_ANDY_LIB_LIBRARY SOURCES += \ andy_native.cpp HEADERS += \ com_andy_EartActivity.h \ andy_native.h firsttarget.target = firsttarget firsttarget.commands += javac -cp /home/user/Android/platforms/android-26/android.jar:/home/user/Unity-2018.1.0b8/Editor/Data/PlaybackEngines/AndroidPlayer/Variations/mono/Release/Classes/classes.jar -sourcepath java/src java/src/com/andy/AndyActivity.java -d java/classes secondtarget.target = secondtarget secondtarget.commands = javah -cp java/src com.andy.AndyActivity lasttarget.target = lasttarget lasttarget.commands = jar cvfM andy.jar -C java/classes . libandy.so QMAKE_EXTRA_TARGETS = firsttarget secondtarget lasttarget PRE_TARGETDEPS = firsttarget secondtarget DISTFILES += \ java/src/com/andy/AndyActivity.java
this will produce first three targets while in first make invocation.
- Than, the last forth target (.jar) has to be built during second make invocation, that is added via QtCreators menu:
note, last two default build steps in QtCreators menu are disabled. This saves compile time. It just adds no value to my goal.
We are the champions! ))
UPDATE: just couple sidenotes for those, who stucks in android's development like I constantly do:
a) packing native libYourNativeLib.so in java's .jar will make it hard to init... so, finally I refused this approach and just left binary lib for deployment as a separate file.
b) if your Android app will crush due to inability to load gnustl_shared, just add this line in qmake's .pro:QMAKE_LIBS_PRIVATE -= -lgnustl_shared