I'm working on application which make use of the org.simalliance.openmobileapi API to use the Secure element communication.
The application is Native that is the main Activity call a JNI library to operate. The JNI library use the JNI Method to call functions of the org.simalliance.openmobileapi package.
The API level is 8 as write in the mainfest:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
The application work fine with Android 2.3.6 but when i try to launch the application from Android 4.0.4 or later the application can't find the SEService class of the org.simalliance.openmobileapi. Useful log are:
09-20 11:00:48.509: I/dalvikvm(1104): Failed resolving Lpkg/wrapper/SecureChannel; interface 203 'Lorg/simalliance/openmobileapi/SEService$CallBack;'
09-20 11:00:48.509: W/dalvikvm(1104): Link of class 'Lpkg/wrapper/SecureChannel;' failed
01-01 22:08:33.460: I/dalvikvm(10881): java.lang.NoClassDefFoundError: org.simalliance.openmobileapi.SEService$1
The class SecureChannel is a Java class that is called by the JNI to operate over the Secure Element and is contained in a jar that is "dexed" at compiling time with the rest of the project.
The package org.simalliance.openmobileapi.jar is contained in the /system/framework folder in both version of Android:
On Android 2.3.6
-rw-r--r-- root root 29148 2012-11-15 11:24 org.simalliance.openmobileapi.jar
On Android 4.0.4
-rw-r--r-- root root 313 2012-06-11 15:49 org.simalliance.openmobileapi.jar
-rw-r--r-- root root 24864 2012-06-11 15:49 org.simalliance.openmobileapi.odex
The only difference i see is the odex file in the Android 4.0.4 OS.
Is there a way to include the classpath or the reference to a package contained in the /system/framework folder ?
I've found a clean solution to this problem.
Instead of saying to the compiler that you want to compile the library into your application, just say that the library is provided for your application and everything will works fine.
In my case I use Gradle with Android studio.
So I just extract the .jar file from the downloaded add-on in my SDK path:
sdk\add-ons\addon-open_mobile_api-giesecke_devrient_gmbh-18\libs
And placed it in my application libs folder.
Then in my build.gradle file I replaced :
dependencies {
compile files('libs/org.simalliance.openmobileapi.jar')
}
with this :
dependencies {
provided files('libs/org.simalliance.openmobileapi.jar')
}
And now everything works just fine.
Here is my configure in Android Studio
in app/build.gradle
dependencies {
compile fileTree(include: ['*.jar'], exclude: ['org.simalliance.openmobileapi.jar'], dir: 'libs')
provided files('libs/org.simalliance.openmobileapi.jar')
}
in AndroidManifest.xml ,turning it true or false depends on you
<uses-library
android:name="org.simalliance.openmobileapi"
android:required="false" />
and in /system/framwork/, "org.simalliance.openmobileapi.jar" is required or an exception will throw up.
I solved the problem putting on src/ folder of my project the source contained in this package:
http://code.google.com/p/seek-for-android/downloads/detail?name=MSC%20Smartcard%20Service%203.0.tar.gz&can=2&q=
More precisely the source in the package com.mobilesecuritycard.openmobileapi.jar which is the new version of the seek-for-android library made to replace the old package org.simalliance.openmobileapi.jar.
I had to rename all the reference to the package from com.mobilesecuritycard to org.simalliance because the SecureChannel class was written with the old package so the old package name must be used.
In android manifest don't forget add:
<application
android:name=....
android:icon="#drawable/icon"
android:label="#string/app_name"
android:allowBackup = "true" >
<!-- support USIM -->
<uses-library
android:name="org.simalliance.openmobileapi"
android:required="false"/>
Related
I create a Jar Lib called "errors" in Java.
I would like to use it in a module called "AndroidHTTPRequestLibrairy" and in my Android App.
But i have a error :
Program type already present:
In my module (AndroidHTTPRequestLibrairy) build.gradle i have :
implementation files('libs/errors-0.1.3-SNAPSHOT.jar')
And in my app I have :
implementation project(path: ':androidhttprequestlibrairy')
and
implementation files('libs/errors-0.1.3-SNAPSHOT.jar')
I dont understand why.
Can someone help me ?
Sincerely,
This issue appears because of namespace conflict.
You are trying to put one library twice in one project. When the Gradle build your project and at the moment when it tries to put in your app.apk archive the errors-0.1.3-SNAPSHOT.jar library it finds out that there is already the errors-0.1.3-SNAPSHOT.jar library and throws an exception.
So the solutions is to remove the implementation files('libs/errors-0.1.3-SNAPSHOT.jar') dependency form the application build.gradle file, because it allready transited in the implementation project(path: ':androidhttprequestlibrairy') dependency
I spent the last three days trying to read an .aar in Android Studio and I just can't figure it out.
My project view looks like this:
--- AnApplication
----------------------.gradle
-----------------------.idea
----------------------- app
-------------------------------- build
-------------------------------- libs
---------------------------------------- cube5-debug.aar
(...)
I want to access a class inside cube5-debug.aar from my main activity.
I know the class is there in the .aar file.
I don't know the precise import line I must write at the start of my main.
I have tried import com.company_cube.cube5 (the package of the project where I generated my .aar) and many other variants.
I don't know if Android Studio is recognizing the file as a library. However, the files sync with the gradle successfully.
(For context, the project where I generated the .aar was made by Unity, by exporting a Unity project into an Android one, and then generating the .aar from that one; the goal was to use this .aar file as a library in a second Android Studio project - the one I am talking about in this post)
I am patiently waiting for any help you can give me. Thanks
EDIT: To import the .aar, I followed the images of this small post:
Importing .aar in android Studio
And solved the error the post reports by putting the .aar in the libs folder like Daniel Nugent said. However, when I try to write, in the Main:
Intent intent = new Intent(getApplicationContext(),UnityPlayerActivity.class);
AS doesn't recognize UnitPlayerActivity. This class is inside the .aar file supposedly. Before making the aar in my first AS project, it was here:
cube5->libs->unity-classes.jar->com.unity3d.player->UnityPlayerActivity
When I open the .aar with Winrar, and open unity-classes.jar with a text editor, I see a almost everything as encoded symbols.
I'm not sure it is normal. Any idea?
EDIT 2: I think I know where the error is: when I import my .aar, I get an IDE fatal error. I don't know how to solve it, so if you can, please check the post I made about it:
IDE fatal error on importing .aar
For android Studio 2.3.3 you can use
repositories {
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(name: 'cube5-debug', ext: 'aar')
}
in the app level build.gradle. I did't check it for AS 3.0.
Add .aar file to your app by doing:
in project build.gradle
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
in app build.gradle
dependencies {
compile(name:'cube5-debug', ext:'aar')
}
So I managed to solve it. The .aar file I talked about was exported with AS, after I imported an Unity project into AS. I did this in order to use the Unity program inside AS. However, this gives error for some versions of Unity and AS. I installed Unity 5.5.0f3 and an older version of AS, and everything worked fine.
Note1: if you aim to install that Unity version, you will be prompted with a requirement of some windows 10 tool, which you must get (I cannot remember the name). I did it by downloading windows 10 install and installing only that tool, which comes with the package.
Note2: I made the program from Unity work inside AS but only because it was a simple program. I later wanted to do an Augmented Reality App in Unity, and use it in AS, but it cannot be done apparently. Evertyting works fine until I import the .aar into AS, and a class in that .aar library gets unresolved ("Video player”). This should have to do with the AR camera class, which AS does not recognize. I ended up creating a AR app with Unity, another app in AS, and from the AS app, calling the Unity app with two lines of code, whenever necessary. To return to the AS app, now in background, I simple click the back button, which is recognized by the Unity app (if you make code in Unity for it) and makes it destroy itself, returning to the AS app.
I am trying to integrate the HockeyApp Android SDK in its latest version 4.1.2 into our Qt Android app. I don't know a lot about Android development or Java in general - nor any Qt or HockeyApp internals.
There is some general official documentation on including third party Android (i.e. Java) libraries into a Qt project; however, it mentions a "Create AndroidManifest.xml button in the Deployment settings" which does not exist in the current Qt Creator 4.2.0 version, so I am unsure as to how outdated this documentation is or what parts possibly still apply.
HockeyApp documentation only covers "typical Android development" using Android Studio and their support is not supportive.
On a side note, integrating the HockeyApp iOS SDK took just a couple of hours and was mostly a matter of writing some Objective C bridge code.
Step 1: Add the SDK to the project
First approach
I tried to follow the above documentation and added the unzipped HockeySDK-Android-4.1.2 folder and a project.properties file with contents
android.library.reference.1=HockeySDK-Android-4.1.2/libs/
to a project folder; I also set ANDROID_PACKAGE_SOURCE_DIR in <my project>.pro to that project folder.
Problem: The androiddeployqt build step issues an error message (wrapped for readability)
Error: <path to build folder>/android-build/HockeySDK-Android-4.1.2/libs
is not a valid project (AndroidManifest.xml not found).
but continues anyway and finally fails with an error message (also wrapped for readability)
BUILD FAILED
/opt/Android/android-sdk-macosx/tools/ant/build.xml:573:
HockeySDK-Android-4.1.2/libs/ resolve to a path
with no project.properties file for project <path to build folder>/android-build
Running androiddeployqt with a --verbose switch adds significantly more output, but zero useful information.
Second approach
The downloaded HockeyApp Android SDK zip archive contains - besides some documentation - a file libs/HockeySDK-4.1.2.aar; from this response and this comment, I gather the AAR format is simply a zip archive that, among others, contains an AndroidManifest.xml file. I unzipped libs/HockeySDK-4.1.2.aar in place, then removed it; now the first error message in the build is gone.
Problem: The build fails with
BUILD FAILED
/opt/Android/android-sdk-macosx/tools/ant/build.xml:597:
The following error occurred while executing this line:
/opt/Android/android-sdk-macosx/tools/ant/build.xml:649:
The following error occurred while executing this line:
/opt/Android/android-sdk-macosx/tools/ant/build.xml:655:
<path to build folder>/android-build/HockeySDK-Android-4.1.2/libs/src does not exist.
Again, adding running --verbose to androiddeployqt adds nothing but noise. Looking into the build.xml locations mentioned doesn't help either.
Update:
I tried simply creating the missing folder from the error message; now the build fails as follows:
-dex:
[dex] input: <path to build folder>/android-build/bin/classes
[dex] input: <path to build folder>/android-build/HockeySDK-Android-4.1.2/libs/bin/classes.jar
[dex] input: <path to build folder>/android-build/libs/QtAndroid-bundled.jar
[dex] input: <path to build folder>/android-build/libs/QtAndroidBearer-bundled.jar
[dex] Pre-Dexing <path to build folder>/android-build/libs/QtAndroid-bundled.jar -> QtAndroid-bundled-a06280f40655c27b25038380a4d7f67c.jar
[dex] Pre-Dexing <path to build folder>/android-build/libs/QtAndroidBearer-bundled.jar -> QtAndroidBearer-bundled-a69fa323dbfa477411ea082423128813.jar
[dex] Converting compiled files and external libraries into <path to build folder>/android-build/bin/classes.dex...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] java.io.FileNotFoundException: <path to build folder>/android-build/HockeySDK-Android-4.1.2/libs/bin/classes.jar (No such file or directory)
[dx] at java.util.zip.ZipFile.open(Native Method)
[dx] at java.util.zip.ZipFile.<init>(ZipFile.java:219)
[dx] at java.util.zip.ZipFile.<init>(ZipFile.java:149)
[dx] at java.util.zip.ZipFile.<init>(ZipFile.java:163)
[dx] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
[dx] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
[dx] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
[dx] at com.android.dx.command.dexer.Main.processOne(Main.java:677)
[dx] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
[dx] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
[dx] at com.android.dx.command.dexer.Main.run(Main.java:277)
[dx] at com.android.dx.command.dexer.Main.main(Main.java:245)
[dx] at com.android.dx.command.Main.main(Main.java:106)
[dx] 1 error; aborting
BUILD FAILED
/opt/Android/android-sdk-macosx/tools/ant/build.xml:888: The following error occurred while executing this line:
/opt/Android/android-sdk-macosx/tools/ant/build.xml:890: The following error occurred while executing this line:
/opt/Android/android-sdk-macosx/tools/ant/build.xml:902: The following error occurred while executing this line:
/opt/Android/android-sdk-macosx/tools/ant/build.xml:283: null returned: 1
I obviously can not just make up some classes.jar file, but there is one single file with that name in <path to build folder>/android-build/HockeySDK-Android-4.1.2/libs, so I can create the missing bin folder and create a symlink in it to ../classes.jar.
The build now succeeds. Step 1 complete.
Step 2: Use the SDK in the project
Going back to the corresponding HockeyApp documentation, I gather I need to modify some code that looks similar to
public class YourActivity extends Activity
...
There is one single occurrence of such code in the project in <path to build folder>/android-build/src/org/qtproject/qt5/android/bindings/QtActivity.java:
public class QtActivity extends Activity
...
That file is copied there by the androiddeployqt tool (part of the Qt SDK) from its source folder inside the Qt SDK at $QTDIR/src/android/java, i.e. /opt/Qt/Qt_5.7.1/5.7/android_armv7/src/android on my machine.
Looking at the androiddeployqt source code, I see there is no way (e.g. by means of a command line parameter) to change the source folder these .java files are taken from, so it is not possible to provide my own set of files and have androiddeployqt copy that instead. Hence, in order to make this work, I must either extend / fix androiddeployqt functionality (sorry, I won't touch that code - yuck!) or modify the copied files at their source directly - which then obviously affects all projects build with that Qt SDK instance.
As a third approach, I could try patching the Java sources after androiddeployqt copied them to the build folder. Unfortunately, this not only makes the development and build workflow absurdly painful; it is also made entirely impossible by the androiddeployqt "one tool does everything" design fail (see below): There is no point in time in the build process where the Java sources exist in the project and the .apk package has not been built yet. I thought the androiddeployqt --no-build parameter would enable that:
--no-build: Do not build the package, it is useful to just install
a package previously built.
but "building" here refers to building the Qt / Java bridge code, not the actual app, so that parameter turns out to be pretty much useless for the task at hand; the build fails with this message - which by itself are a bug as the .apk file from the message does not exist and thus the Android package build was not successful:
Android package built successfully in 1.011 ms.
-- File: <path to build folder>/android-build//bin/QtApp-release-unsigned.apk
Sure, I could copy the sources elsewhere, patch and copy them manually to their final destination, but I think this is where I draw the line.
Actually, looking at the androiddeployqt source code is where the buck stops. Too much time has already been wasted trying to get dysfunctional tools to work:
I will not comment on how smart it is to write a build tool in C++ in the first place - in a single, ~3000 line main.cpp file
I will not comment on the practice of hardcoding the src/android/java path (and many other paths) in the androiddeployqt sources not once, but multiple times - instead of a const QString that at least prepares appropriate (i.e. external) tool configuration
I will not comment on how smart it is to violate the ~50 year old best practice of one tool, one purpose - and duplicate large amounts of functionality provided by Qt, Android or Java tools, such as building, signing, deploying, installing packages, etc.
However, the fact that this tool has made it past code review into a number of major Qt release is nothing short of frightening - and probably a good indicator that it's time to consider dropping Qt as a technology in general
While I am writing this, the Qt 5.8.0 installation keeps freezing, maxing out one CPU core - and has been doing so for the last ~12 hours. I rest my case.
My questions
has anyone had any success with Qt, Android and HockeyApp ?
does anyone have any hints / pointers / wild guesses as to what is wrong here ?
no further questions; I've seen enough
Step 3: Call SDK Java code from C++
(cancelled due to brickwall in step 2)
Answering my own question:
Using the HockeyApp SDK with Qt on Android is not possible without either patching Qt SDK tool source code or Qt SDK Java template source files.
In fact, from what I gather, it is not possible to use any third party libraries with Qt on Android if they require Java source code modification.
FWIW this is an AndroidManifest.xml I use for an app, no external library dependencies though. You could try adding+modifying this to get the deploy to work?
File structure:
/my-project-dir
├── android
│ ├── AndroidManifest.xml
│ └── res
│ └── drawable-mdpi
│ └── icon.png
├── my-project.pro
AndroidManifest.xml:
<?xml version="1.0"?>
<manifest package="my_package_name" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="my_app_name" android:icon="#drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="my_app_name" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="#array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="#array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="#array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="#array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="#array/bundled_in_assets"/>
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Messages maps -->
<meta-data android:value="#string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="#string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="#string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps -->
<!-- Splash screen -->
<!--
<meta-data android:name="android.app.splash_screen_drawable" android:resource="#drawable/logo"/>
-->
<!-- Splash screen -->
</activity>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->
<!-- %%INSERT_FEATURES -->
<!-- %%INSERT_PERMISSIONS -->
</manifest>
I am working on a code that was made in the Eclipse and i am migrating to Android Studio, however i am having a problem to the to import
com.google.android.maps.GeoPoint;
but i can import
com.google.android.gms.maps.GoogleMap;
I've tried to add in my Gradle file
compile 'com.google.android.gms:play-services:6.5.87'
and also i've tried also to use .jar, however i didn't have good results.
compile files('libs/google-play-services.jar')
I searched about this in many places, but i found nothing to help me, case somebody have resolved this problem and want help me i thank you.
To work, i had that to replace the below line in the my Gradle file.
android {
...
compileSdkVersion 16
...
}
To
android {
...
compileSdkVersion "Google Inc.:Google APIs:16"
...
}
Please following all the steps to Add Google Play Services to Your Project in Android Studio:
1.Open the build.gradle file inside your application module directory.
Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.
2.Add a new build rule under dependencies for the latest version of play-services. For example:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Be sure you update this version number each time Google Play services is updated.
Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them. For information on how to do this, see Selectively compiling APIs into your executable.
3.Save the changes and click Sync Project with Gradle Files in the toolbar.
4.Open your app's manifest file and add the following tag as a child of the element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You can now begin developing features with the Google Play services APIs.
Please refer to here for more details.
I tried to import com.google.maps.android:android-maps-utils to my project in Android Studio 0.5.4.
I get this Gradle Information and Error:
Information:[C:\Users\Gast1_000\android studio projects\GeoPicture\app\build\exploded-aar\com.google.maps.android\android-maps-utils\0.3\AndroidManifest.xml:2, C:\Users\Gast1_000\android studio projects\GeoPicture\app\build\exploded-aar\com.google.android.gms\play-services\4.3.23\AndroidManifest.xml:3] Main manifest has <uses-sdk android:minSdkVersion='8'> but library uses minSdkVersion='9'
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merging failed. See console for more info.
My build.gradle:
dependencies {
compile 'com.android.support:support-v13:+'
compile 'com.google.android.gms:play-services:4.3.+'
compile 'com.google.maps.android:android-maps-utils:0.3'
}
Project Manifest.xml
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
I tried to change the minSdk version manually in the manifest of the maps-utils, but with each gradle sync it chnage it back.
Is there any other possiblility to add the library in AS 0.5.4?
This seems to be a bug at the moment: https://github.com/googlemaps/android-maps-utils/issues/60
If Gradle overwrites you changes, just use Gradle to do these changes (as suggested in the above link) ;)
Add the following code block to your build file inside the android { .. } block.
applicationVariants.all{ variant ->
variant.processManifest.doFirst {
File manifestFile = file("${buildDir}/exploded-aar/com.google.maps.android/android-maps-utils/0.3/AndroidManifest.xml")
if (manifestFile.exists()) {
String content = manifestFile.getText('UTF-8')
content = content.replaceAll(/minSdkVersion="8"/, 'minSdkVersion=\"9\"')
manifestFile.write(content, 'UTF-8')
}
}
}
This of course isn't the best solution, but should do it until the bug is fixed:
https://code.google.com/p/android/issues/detail?id=66109 (Ignore minSdkVersions when matching libraries)