How to: Target a local android dependency - android

I'm trying to modify a flutter package but the part that needs changing is in an Android dependency being used by that package.
The flutter package is epub_viewer (https://pub.dev/packages/epub_viewer) which implements a modified version of FolioReader (https://github.com/JideGuru/Folioreader-Android) ...
I've been trying to follow examples on here but it doesn't make sense and keeps telling me it can't find the package https://developer.android.com/studio/build/dependencies
My file structure is like this:
../users/documents/epub_viewer
../users/documents/folioreader
and I need to change this dependency in epub_viewer's app build.gradle
dependencies {
implementation "com.jideguru:folioreader:0.6.2"
...
}

Related

Override java dependency in react native library

I need to use a react native library called #ihealth/ihealthlibrary-react-native
I added it to my project, but on build I get an error Could not find no.nordicsemi.android:dfu:1.6.1
This package version seems to be no longer available, so I would like to override the version in my react native app.
I added the following in MyProject/android/app/build.gradle
dependencies {
implementation("com.ihealth.ihealthlibrary:iHealthLibrary:1.5.1") {
exclude group:'no.nordicsemi.android:dfu:1.6.1'
}
implementation("no.nordicsemi.android:dfu:1.8.0")
}
I then get this error: Could not find com.ihealth.ihealthlibrary:iHealthLibrary:1.5.1.
Basically I can't figure out what's the correct package name and version to put in my config.
Where can I find this ?
This lib is really outdated. Go into the libraries build.gradle file and replace this implementation 'no.nordicsemi.android:dfu:1.6.1'
with: implementation 'no.nordicsemi.android:dfu:1.8.0'
then create a patch: yarn patch-package #ihealth/ihealthlibrary-react-native

Flutter - compile android dependency from local instead of remote repository

I'm creating a flutter ebook reader app using a package named epub_viewer that uses Folioreader for reading ebooks. but I need to make some customizations in the main library Folioreader for my project so I've tried to add Folioreader as a library for making my customizations and testing the package.
this is the original ebpub_viewer build.gradle dependencies part:
dependencies {
implementation "com.jideguru:folioreader:0.6.2"
.....
}
So i changed this to :
dependencies {
//implementation "com.jideguru:folioreader:0.6.2"
implementation project(':folioreader')
....
}
And putting the Folioreader inside the project using android studio module import but i got some errors:
Build file '/home/user/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/epub_viewer-0.2.5/folioreader/build.gradle' line: 1
A problem occurred evaluating project ':folioreader'.
> Plugin with id 'com.android.library' not found.
Can anybody guide me on how to solve this problem? or maybe a better solution for editing Folioreader from and source and test it in the final flutter app? thanks.

Add Flutter functionality as a dependency in android library

Why do I need this?
I'm creating a Flutter package (for android) and I want to create the MethodCallHandler's code in a separate AAR file that can be added in my plugin's code
So I'll have:
pluginNativeCode/android/MyPlugin.kt
import ir.malv.android.flutter.MySeparateMethodCallHandler
class MyFlutterPlugin: FlutterPlugin {
override fun onAttachedToEngine(...) {
// Here's the source of the problem
channel.setMethodCallHandler(MySeparateMethodCallHandler())
}
}
The MySeparateMethodCallHandler is not in the plugin/android part and it's imported as a gradle dependency
However in that library I don't have access to flutter's codes like MethodCallHandler class.
Similar behaviour in unity and react native
In react-native there is com.facebook.react:react-native:+ that can be added as compileOnly to get the needed react-native codes
In unity we have unity.jar file which contains unity native codes and can be added as compileOnly as well to provide engine's native APIs
What do we have in Flutter for this?
Is there a dependency that I can include as compileOnly and use it to get the needed classes and create my aar file in a separate project?
Here's a solution:
Add this remote to repositories of build.gradle
allprojects {
repositories {
// .. rest of remote urls
maven { url("http://download.flutter.io/")}
}
}
Add this dependency to module's build.gradle
dependencies {
compileOnly("io.flutter:flutter_embedding_debug:1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718")
// rest
}
Notice the compileOnly. This will avoid the class duplication. Plugin just requires it. The flutter app will provide it itself.
What is 0fdb562ac8068ce3dda6b69aca3f355f4d1d2718? It's the engine version that is good to match the version you are developing the plugin with.
in your code you will have access to needed classes such as MethodChannel, MethodChannel.Result and ...
Bonus: How do I know what engine I'm making the plugin with?
I think it should not matter if you just need a class like MethodChannel to invoke a method, but here's a way to get it using Android Studio
Open the project/example/android of your plugin using Android studio (that has Flutter plugin activated)
run gradle plugin_name:dependencies task and look for flutter_embedding_ phrase.

Adding and debugging external project

I am developing an android app. I have added a new project to my gradle build as follows....
In the build.gradle I have added...
android {
dependencies {
implementation project(':code-scanner')
}
...
}
In the settings.gradle I have added...
include ":code-scanner"
project(':code-scanner').projectDir = new File(settingsDir , "../External/code-scanner")
The project builds fine. But I would like to be able to browse the source, and add breakpoints to the code-scanner project, but it does not show up in Android Studio.
I have tried importing module , but the folder is missing from the subsequent select folder dialog.
How can I add this code to android studio, and set breakpoints and debug....
Just in case. Based on Android Documentation dependencies should be defined outside android block. Maybe Gradle Build figures out your code, but your Android Studio can't find source code of your library.
What version of Android Studio are you using?
1- Make sure you put implementation project(':code-scanner') in app level build.gradle file
2- dependencies block should not be inside android block:
Not like this:
android {
dependencies {
implementation project(':code-scanner')
}
}
But like this:
android {
...
...
}
dependencies {
implementation project(':code-scanner')
}
I don't know which IDE you are using but most IDEs like Android Studio or IntelliJ look like the pictures below.
Or you can view your folder structure in Project view like this:
If you didn't accidentally delete it, it should be there.
The actual problem is the location of the project, which is outside of the root project directory:
include ":code-scanner"
// project(':code-scanner').projectDir = new File(settingsDir , "../External/code-scanner")
Better add it as a library module within the root project, then the code should be within IDE scope.
If you don't want to move the project into there, you could put a built artifact into the libs directory.
Adding a symbolic link might also work out (it's rather a file-system issue than a Gradle issue).
'code-scanner' project you have to add as a library to the current project,for that in code-scanner build.gradle file you have to add
apply plugin: 'com.android.library'
please check if it is missing.

How do I use another library in my app?

The title is a little misleading but I honestly don't know how to word it in any other way. This is my project structure:
I want to use the highlighted (fasteranimationscontainer-master) in my current app that I'm working on. I imported it by putting the jar file in my library folder then adding it to my library through Android Studio. But I try to create an object of that imported library, it doesn't show up/import.
I'm still learning how to use android studio so any help would be much appreciated!
1. Library with only the Source Code
To include a library with only the source code (like FasterAnimationsContainer) to your project, you only need to import it as a module from File -> New-> Import Module in Android Studio:
There should be a dialog for the project folder, enter the path where your library reside.
Then you need to add the module to your app build.gradle as a dependency:
android {
...
dependencies {
...
compile project(':fasteranimationscontainer')
...
}
}
Now you can use it in your project.
2. Library from Maven or JCenter
To add dependencies to your project where the library has uploaded to maven or jcenter, you need to modify your app build.gradle file and add extra lines configuring the packages you require. For example, for certain Google or Android, dependencies look like:
android {
...
dependencies {
// Google Play Services
compile 'com.google.android.gms:play-services:6.5.+'
// Support Libraries
compile 'com.android.support:support-v4:22.2.1'
}
}
Try to always read the library README first.
Suggestion:
If you still learning using Android Studio, you can read Using Android Studio. Then read Getting Started with Gradle, because Android Studio is tightly related with Gradle.

Categories

Resources