Android: Add possibility to provide app main lib name without metadata

Normally, the app's main library's name is read from a metadata field
in the AndroidManifest.xml file, which is filled out by
androiddeployqt.
Add a protected variable in QtLoader for the app main library name
that can be set to provide the library name without the metadata field.
This is useful in cases where we don't have a manifest file filled
by androiddeployqt, for example when embedding QML to an existing
Android app.
As a side effect, change the name of existing variable for the main
library and the method to access it to make it more explicit they refer
to the library's absolute path.

Change-Id: I869547818f4d0272668a1052d7bc6916b7bf5a98
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 8e9918e476430cc30007f2acf69f0c0fe120a03d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-01-10 12:27:34 +02:00 committed by Qt Cherry-pick Bot
parent c4dfea83b6
commit ccd624eacc
3 changed files with 22 additions and 8 deletions

View File

@ -104,7 +104,7 @@ public class QtActivityBase extends Activity
loader.loadQtLibraries();
m_delegate.startNativeApplication(loader.getApplicationParameters(),
loader.getMainLibrary());
loader.getMainLibraryPath());
}
@Override

View File

@ -37,7 +37,8 @@ abstract class QtLoader {
protected final ContextWrapper m_context;
protected ComponentInfo m_contextInfo;
protected String m_mainLib;
protected String m_mainLibPath;
protected String m_mainLibName;
protected String m_applicationParameters = "";
protected HashMap<String, String> m_environmentVariables = new HashMap<>();
@ -155,8 +156,19 @@ abstract class QtLoader {
* Returns the context's main library absolute path,
* or null if the library hasn't been loaded yet.
**/
public String getMainLibrary() {
return m_mainLib;
public String getMainLibraryPath() {
return m_mainLibPath;
}
/**
* Set the name of the main app library to libName, which is the name of the library,
* not including the path, target architecture or .so suffix. This matches the target name
* of the app target in CMakeLists.txt.
* This method can be used when the name is not provided by androiddeployqt, for example when
* embedding QML views to a native Android app.
**/
public void setMainLibraryName(String libName) {
m_mainLibName = libName;
}
/**
@ -396,8 +408,10 @@ abstract class QtLoader {
return;
}
if (m_mainLibName == null)
m_mainLibName = getMetaData("android.app.lib_name");
// Load main lib
if (!loadMainLibrary(getMetaData("android.app.lib_name") + "_" + m_preferredAbi)) {
if (!loadMainLibrary(m_mainLibName + "_" + m_preferredAbi)) {
Log.e(QtTAG, "Loading main library failed");
finish();
}
@ -456,8 +470,8 @@ abstract class QtLoader {
String mainLibPath = getLibrariesFullPaths(oneEntryArray).get(0);
final boolean[] success = {true};
QtNative.getQtThread().run(() -> {
m_mainLib = loadLibraryHelper(mainLibPath);
if (m_mainLib == null)
m_mainLibPath = loadLibraryHelper(mainLibPath);
if (m_mainLibPath == null)
success[0] = false;
});

View File

@ -27,7 +27,7 @@ public class QtServiceBase extends Service {
QtServiceLoader loader = new QtServiceLoader(this);
loader.loadQtLibraries();
QtNative.startApplication(loader.getApplicationParameters(), loader.getMainLibrary());
QtNative.startApplication(loader.getApplicationParameters(), loader.getMainLibraryPath());
QtNative.setApplicationState(QtNative.ApplicationState.ApplicationHidden);
}