Android Studio - Hide aar modules dependencies in another aar module - java

I'm facing a problem while developing a library with Android Studio.
The concept is to create one aar (MyLib) which is depends on other aar.
At the end, I want to hide everything from the other aar, and only exposed 'MyLib'.
So I found this tool: 'com.kezong.fat-aar' which give me the ability to create one big fat aar from 'multiple aar'.
Then I have created a ProGuard to only include (-keep) some classes of 'MyLib'.
It works but I can still access to classes defined in the 'multiple aar'.
I've made some online research and I can't find any solution.
Now I wonder if it's even possible to achieve what I want because 'MyLib' should access to the 'multiple aar' (dependencies) but I don't want that the user or client can see them.
Sorry for my bad english...
Do you have any clue or information to help me ?
Thanks a lot.

Related

Is it possible to use links file java class files instead of copying them into project in Android Studio?

I have many java class files written by me for common purposes which I need to use very often in my Android projects. These classes (let's call them 'library') has many static methods in them and I call these methods when I need them in my Android Studio projects without any problem
When I create a new Android Studio project I copy all those library files into the Java folder of my new project. So, I can call them with the syntax like classname.methodname() at any time in my projects (in activities, in other java classes, etc)
The question is that this technic causes many independent library files in each project. This means that, when I have added a new method or changed a method, I need to do the same thing at each library files in each project.
As I am new at Android Studio and I am playing with that at the moment, this might be ok. But in real life, this will be impossible in the near future while I was struggling with many projects.
I am sure that, there should be a way to use file links instead of inserting these library files by copying them into the Android projects. So, making changes in a source library file will affect all projects at once. Something like $I directive in the C type languages...
Is this possible and if yes, how?
Thank you...
One good way would be to create your own library/module in android studio.
Here is a link for that : https://developer.android.com/studio/projects/android-library
And another way would be to create your own JAR file.

Migrate an existing app in playstore from java to kotlin

this is more a theoretical question.
I have an app that is already in the playstore. This app has been working since the year 2017, so it has a lot of old libraries. The goal is to migrate it to kotlin. So, what's more effective to achive this goal:
Migrate file by file to kotlin
Create a new project with same buil.gradle in order to have the same id application. But at this point have another question, if I create a new app with the same id, package name.. can I generate a signed bundle apk with my old credentials?
I'm not pretty sure how to achive this goal. If there is a better I would really appreciate it you can teach me how.
Thanks!
The good point with Kotlin is that it can operate together with Java easily. To rewrite the app completely seems like a lot of work which would need an important reason. You can rewrite file by file and this way keep all functionality working.
If you keep the application Id in a new project, you can update your existing app only if you sign it with your old keystore. These are the two factors that identify your app.
I recently converted an existing application to Kotlin.
Before you start, if you have not done so, I would recommend converting
your application to AndroidX. It will save you a lot of headaches.
**Android Studio Refactor/Migrate to AndroidX**
Note that during the conversion it will miss libraries and dependencies if you use
variables in your gradle file. When that is done and stable then go to Kotlin.
1: Add in the Kolin Libraries
Project Gradle -
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71"
Module Gradle ( **3 library choices - stdlib, jdk7, jdk8** )
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
2: Add the plugins to the Module Gradle
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
3: Converted the java files one by one using the automatic code conversion.
Android Studio - Code/Convert Java class to Kotlin
Note that you will have breakage, mostly around parameter passing. You will need to
become conversant with ( !!, ? and let )
Another thing, as long as you have the Kotlin extension plugin you no longer need
a library for dependency injection. You can pull out all of the Butterknife code.
I would NOT create a new application. I assume you are in bitbucket or github. Why
hang on to the past. Convert and go on with your life.
Hope you find this useful.

How to download Packages for Android Studio?

I just started Android Development yesterday and just finished with my first Activity. On running it, I'm getting errors like
**Error:(4, 37) error: package android.support.design.widget does not exist**
As I never post without it, I've already done plenty of searching on this. Basically, what I've understood is that it couldn't find that Widget Package on my PC. So, do I have to download it? If yes, then how?
People on internet had similar problem with Packages and almost every post has different answer to this. Some say change your Gradle File others say Update your Studio (have done it).
Any kind of explanation or bit of knowledge with the solution would be highly appreciated. I'm a kind of geek who want to get concepts and basics clear. So, it would be great if you include the reason and technicality behind this too with your answer. Thanks. :)
It's a design library for Android apps development and as #Dominique pointed have a look at that page and copy paste that compile 'com.android.support:design:22.2.0' line in your project gradle file and press the sync button. Your project will sync in a few moments and the design library will be downloaded. Now you can use this library and there won't be any errors.
No, in Java "package" is not a "library" or a "piece of software" (like it is in some other languages). Package is what classes belong to - you might think of packages as directories containing Java files (it is a simplification, but it works). In Java libraries are packaged into (usually) "jars" (those jars usually contain classes divided into packages), so what you need to download is "jar".
So, first thing you need to check is: what library contains the package, and configure your IDE accordingly. The package in question belongs, I think to the so called android support library, which you can install using the SDK tool.

java.lang.NoSuchFieldError caused by 3rd Party module

I've integrated a third party library in my Android project.
The library is provided in form of an .aar file.
Implementation of it, is a simple one-liner that creates a customdialog in my mainactiviy.
But whenever it tries to create the dialog my app will crash with
java.lang.NoSuchFieldError: de.thirdparty.lib.R$id.neverParticipateButton
at de.thirdparty.lib.views.DialogBuilder.buildView(DialogBuilder.java:97)
I have implemented the library in a new empty android project and it worked as planned. So it seems like there's a conflict with my project.
I've read in a different post (Here), that it can be caused when project and library accidentally use the same name for a layout. But when i inspect the library's code in my build folder, I can't find any layouts that use the same names. Also not ids or drawables.
Does somebody have an idea what else can cause this Error, or advice how to debug?
Kind Regards
Christian
Problem was that another 3rd Party library that was already integrated in my app had the same layout name as the new one... Nothing much i could do here but to inform the devs of the libs to use prefixes.

Android: Adding a new framework

I am trying to add a new framework in Android Source code and call my applications using that framework.
I have included my framework files and called the functions. Makefile for the application includes the new framework. Everything compiles. But when I run my app it force closes. All the Xml layouts and java classes are fine. Manifest file includes
<user-library android:name="frameworkName">
My question is where to have the mapping for this "frameworkName" in android base code so that it is able to figure out the framework folder/path. Which looks like to be the main problem
What are the possible steps to make this work as I am unable to run my application(Force Close).
EDIT: Initially I was getting Runtime Exception:-Class Not Found for framework classes. Moreover that error was coming up when I missed the "user-library" tag. Now after adding the tag, my apk is not getting installed by the package manager as it is not able to figure out the the framework path.
Android Developers says this:- "the PackageManager framework won't let the user install the application unless the library is present on the user's device".
http://developer.android.com/guide/topics/manifest/uses-library-element.html
So which linking am I missing. Any guesses or help would be really helpful for me.
thanks
Instead of "frameworkName", you should put package name of your library (the one defined in the application name of your library).
If your classes (and R) are in com.example.myframework, then that's your library name.

Categories