I have confusion that how the android packaging works with library, Say i am used some kotlin experimental apis in my application.I have published the application, Say After the production the experimental api which i have used have major change.
Does my app which is already published get affected?
Can anyone resolve my confusion?
Android Packaging are the group of libraries that you used for your particular task.
Suppose you want to use retrofit Networking library in your project, However, you need to use some callback method and those callback methods will import via package.
Here one more practical example, you want to work with Java then JAVA SDK here, you have to set in environment variable then you use methods in your framework.
Now let me come of Effection, so yes some libraries got update and some deprecate due to advancement feature. Yes, it impacts on your project. not in meantime but yes in future if there is any advance feature.
Related
I am new to Android development. I have the question if and how it is possible to use Android-framework code, like e.g. USBManager in a Java-module in Android-Studio. Or do I have to convert it to something else to do the trick?
Cheers
David
As I am currently not able to use imports like android.v7.etc..
Yes, it's possible to use android specific code in java, when you create any new project using android studio, necessary files are made available to you.
To use any android specific library first you need to ensure whether it's
directly available to you or you need any additional 3rd party library(that can be imported in app level build.gradle file).
Considering your example of USBManager (package : android.hardware.usb.UsbManager) write 'USBManager' and press Alt+Enter key, this will give you option to import the corresponding class from appropriate package.
If you still find any error, please comment.
David,
For android application development you can use following
- Android SDK java classes
- Android NDK
- Android support library
- native code as jni library(you can write your own native code or create wrapper over existing android framework library)
I have found the answer in the android documentation. Java-modules are not meant to use the Android-framework. You must use an Android-library for that (There's also an option to create a Java Library, which builds a traditional JAR file. While a JAR file is useful for many projects— especially when you want to share code with other platforms—it does not allow you to include Android resources or manifest files, which is very useful for code reuse in Android projects. So this guide focuses on creating Android libraries. https://developer.android.com/studio/projects/android-library)
Cheers
David
I'm on a team with multiple developers. We're using JUnit5 via android-junit5 and tests written using the #Test annotation from the org.junit package as opposed to the org.junit.jupiter.api package are excluded from gradle's test reporting. I'd like to, if possible, outright prevent developers from using org.junit. Is there a way to do this using gradle? I'd like to achieve this particular solution and not a workaround as there are other instances that we'd like to prevent users from using a given package (java.time.* in Java 8 vs ThreeTenABP)
Thank you
One way of approaching the problem could be to create a Jar that contains only the allowed APIs. You could then upload that jar to an repository and ask developers to use it as a testCompileOnly dependency while keeping the original jar as a testRuntimeOnly dependency.
This will guarantee that test code cannot access the forbidden classes/packages since it will not see them during compilation.
we just upgrade our Nexus 96 to Android N and now get the following popup while working with our app:
give me some suggestions
Check reported same issue:
https://github.com/litehelpers/Cordova-sqlcipher-adapter/issues/41
Now it has already been resolved.
For reference:
sqlcipher/android-database-sqlcipher#216
You can check SQLCipher for Android Release—Android N Support on below link:
https://discuss.zetetic.net/t/sqlcipher-for-android-release-android-n-support/1465
EDIT:
You can also check
NDK Apps Linking to Platform Libraries for private libraries usage.
Check "Update your app" section which provides steps to fix these types of errors.
You are probably using a native library that is directly accessing private APIs. The issue is described below.
From Android Developers Blog https://android-developers.googleblog.com/2016/06/android-changes-for-ndk-developers.html:
Private API (Enforced since API 24)
Native libraries must use only public API http://developer.android.com/ndk/guides/stable_apis.html?utm_campaign=android_discussion_ndkchanges_062716&utm_source=anddev&utm_medium=blog, and must not link against non-NDK platform libraries. Starting with API 24 this rule is enforced and applications are no longer able to load non-NDK platform libraries. The rule is enforced by the dynamic linker, so non-public libraries are not accessible regardless of the way code tries to load them: System.loadLibrary(...), DT_NEEDED entries, and direct calls to dlopen(...) will fail in exactly the same way.
(...)
Potential problems: starting from API 24 the dynamic linker will not load private libraries, preventing the application from loading.
Resolution: rewrite your native code to rely only on public API. As a short term workaround, platform libraries without complex dependencies (libcutils.so) can be copied to the project. As a long term solution the relevant code must be copied to the project tree. SSL/Media/JNI internal/binder APIs should not be accessed from the native code. When necessary, native code should call appropriate public Java API methods.
A complete list of public libraries is available within the NDK, under platforms/android-API/usr/lib.
As other answers pointed, it seems that this API 24 issue has been solved.
I like the Kotlin REPL in Idea / Android-Studio - but as an Android Developer I often run into Stub! problems here. When writing unit-tests I am using unmock to work around this problem. Is there a way to use the same method used there for the Kotlin REPL plugin?
[
All android (and java.lang.*) classes are placeholders in an Android project. This is because android does not use standard java class files to store the compiled code and there is no way to directly run this code on a computer.
You simply can't use the REPL with android classes, they will only exist on an actual device or emulator.
If you do not care about correctness, then you can use Robolectric's implementation of Android by adding it as a dependency to the project.
To make sure it does not collide with the actual implementation you should probably do this with a separate module dedicated to the REPL.
Robolectic's dependency used by unmock is: org.robolectric:android-all:7.1.0_r7-robolectric-0
The problem is that the Kotlin REPL in IDEA is provided by the Kotlin IDEA plugin, which has no notion of Android per se, but only looks at what's in the classpath, which in this case is the android.jar containing the stubs that throw the exception you mentioned.
Using unmock or even the integrated Android support for removing exceptions from the stubs in tests (see here at the end of "Mock Android dependencies") won't work as that only affects your Gradle build.
The only solution I can think of is to either open an issue on the Kotlin tracker or dig through the source code of the REPL function in the Kotlin plugin and send a Pull Request.
I am creating a cross platform application in java using libgdx. I am using Json in the core project and was trying to deploy on Android when I received this error:
E/AndroidRuntime(2030): java.lang.NoSuchMethodError: org.json.JSONObject.getNames
I read around and I found out that Android has a built in Json library that uses that same package name as the Json library I added to my core project. The library I use has the getName() method and the Android library has a name() method. Is there a way for me to specify the library I want to use? Alternatively, is there a way for me to ignore the Android library?
Update: I tested accessing the JSON method in my android project using
JSONObject.getNames(TEST);
which should have given me null, but instead gave me the same error.
if you happen to use a lib, that uses the same namespace/package name as another, you are at the mercy of the classloader, which usually picks the first place, where it can find the class by name.
so the easiest way to circumvent this is either to use the same library and version as used on android or move your library in another package.
if the library in question allows it (licence etc) and is reasonable small, you might be easier off just pulling in the source files in your project and let the IDE do the refactoring magic. Also there are tools like jarjar.
There are some question on SO (Calling same Method having same packageName From Different JARs, Java, Classpath, Classloading => Multiple Versions of the same jar/project). So you might be able to circumvent this problem, but my gut feeling is, that you will end up in big mess.