I am trying to use Shimmer library and a Slider View library together.
Unfortunately, there's a custom attributes in both libraries that is conflicting: I am getting a duplicate attribute found error.
I have read that this is a bug and there are no solutions as of now and we cant create custom attributes within the context of each library. But is there any other way around it apart from me implementing the slider view myself?
Android resource compilation failed
app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:4619: error: duplicate value for resource 'attr/shape' with config ''.
\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:4619: error: resource previously defined here.
\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml: error: file failed to compile.````
I think there's an workaround for that issue. However, I'm not sure if you can do that due to licensing.
I didn't test it. Not sure if it will work. But I think you can try. If that does not work, let me know and I delete the answer.
To avoid that error, you can resort to the fact that you have access to the source code of the AndroidImageSlider. This way, instead of adding that library as an AAR file, you can import the source code as a module.
This way, you can rename the attr/shape and it will be re-compiled as part of your project.
1) Remove the AndroidImageSlider from your project (from build.gradle etc)
2) Then, create a new module called "library" (File -> Project Structure -> Modules -> + -> Android Library)
3) This will create a new folder to your project <ProjectPath>/library
4) Download the Library Source (using git or as a zip file) and replace the content of the library folder with content from library folder that you downloaded (you can ignore all other folders... You can replace the files of same name).
5) Remove file library/gradle-mvn-push.gradle and remove following line from: library/build.gradle:
apply from: './gradle-mvn-push.gradle'
6) Add following lines to your app/build.gradle
dependencies {
...
implementation project(":library")
...
}
7) Sync and Rebuild your project.
8) Open the file ./library/src/main/res/values/attrs.xml and rename the atribute shape (customShape for example).
9) Try to build again. Some errors may happen since you renamed that attribute. Fix them.
10) You can add the view to your layout as follows:
This will allow you to compile your project. The downside is that you are responsible to fix/update the library by yourself. On the other hand, you have control over the libraries build.gradle and then, you can update the build tools version, support library version etc.
Anyway, this may help you
Related
I have a set of utils and custom widgets that I want to pull out of my project as an Android library so that I can use them in other projects (and possibly share in the future). I created a new Android Studio project and changed the build.gradle file so that 'com.android.application' was 'com.android.library' and deleted the applicationId. It all compiles fine and I have a .aar file created.
I now want to use this new library as a module in my original project. When I do an Import Project, all the files from the library project are copied into my original project. But I don't want that because if I change the imported library code, it isn't reflected in the library project or vice versa.
I also tried adding this to settings.gradle:
include ':myutils'
project(':myutils').projectDir = new File(settingsDir, '../../../../Development/MyUtils/')
and in the original project app build.gradle:
dependencies {
implementation project(':myutils')
...
But I get this error:
ERROR: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve project :myutils.
Show Details
Affected Modules: app
How can I link the library to my project without importing it? I would prefer not to go through an external maven repo yet. I'm happy to (and would expect to) recompile my library whenever there is a change there and then rebuild my original project.
Thank you in advance.
I think I just had the same problem - I wanted to put the library .aar file somewhere on my local drive and then use it in a new app as a dependency. I didn't want to have to go through a repo or to include it in the libs folder in the new app. Hopefully that is what the OP asked and the following might be of help to others.
Searching on SO (Aug 2021), majority of answers seemed much more involved than what Android Studio offers (tested on version 4.2). That is, an .aar file that lives outside the app project can now be added as an implementation file in the gradle dependencies. So, it doesn't have to go through a repo, and it doesn't have to be included in the libs folder in the project.
The current documentation (Aug 2021) gives a fairly straightforward answer how to do it:
https://developer.android.com/studio/projects/android-library#psd-add-aar-jar-dependency
In short, if you have put your .aar file somewhere on your local drive, this is how to add it as an implementation file in another app project:
In Android Studio, in your new app project, go to: File > Project Structure > Dependencies.
In: Modules > app > Declared Dependencies, click '+' and select 'Jar Dependency'. (Even though you are trying to use an .aar file, you still select 'Jar Dependency').
In the 'Add Jar/Aar Dependency' popup dialog:
in step 1 enter the path to your .aar file on your local drive, and
in step 2 select 'implementation'.
If everything worked out, your build.gradle(Module) should have a line in the dependencies that looks like:
dependencies {
implementation files('../../../MyFolder/MyLibraryFile.aar')
A few notes:
You can actually just add the dependency manually, by typing it into the build.gradle(Module) dependencies, so you don't actually have to go through the Android Studio dialog outlined above.
you can either use a relative path (as the example above), or an absolute path.
the Android Studio dialog is somewhat limited in that you cannot just browse to your file (in point 3, step 1), but you have to actually enter the path manually.
Probably the most important: Whenever you make a change in the library and assemble a new .aar file, then remember to do the following in your app project that uses the .aar file as a dependency: Clean Project, then Sync Project with Gradle Files, and only then run the app, so that the changes in the library could take effect in your app.
I have been using Phgr's above technique for four years. I have three comments -
First, I don't clean the app project each time I change the library - I just do a Sync Project before building and testing the app.
Second, I changed the File-Settings-Keymap-Main Menu-File-Sync to Alt-S for easy of syncing - I hate wasting time using the mouse for selecting the Sync icon.
Third, I have an implementation line in the app's build module file for each app variant such as the following -
debugImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-debug.aar')
releaseImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-release.aar')
All of this is working fine with Android Studio 4.2.2 and sdk version 30.
Hope this helps others with this problem
I have a layout file that includes controls that are part of a library module that is compiled in the project.
IntelliJ reports that it can't dispaly the control, despite that it shows up properly when running the actual android app on my device.
It suggests rebuilding the project, creating the class, or fixing my build path.
The module that has the controls are in the Dependencies tab, and are set to Export, and Scope=Compile.
The layout file references the custom controls via their fully qualified package/class name.
The rendering API I've selected is the same version as my Target SDK set in my AndroidMainfest.xml
I have tried both using a tag with the class attribute pointing to the class, as well as a tag where the tag name is the fully qualified class. Both result in IntelliJ not being able to render the view.
I was able to solve this by specifying a Project compiler output directory at the IntelliJ project level. Prior to this fix, my library modules used an output path as a subdirectory of where the module is defined.
File > Project Structure > Project compiler output.
Set it to the standard "\out"
Next, I set my library modules up to use the inherited project output path.
Project Settings > Modules > [library module name] > android > Packaging Tab > "Use resources directory specified at "Structure" section radio button.
Also make sure that "Include assets from dependencies into APK is set.
I have a custom library that needs to be referenced in about 10 projects. Everything works fine in Eclipse but I want to migrate them to Android Studio in order to take advantage of the build system. I've already check
Android studio add external project to build.gradle
How to share a single library source across multiple projects
and some other links and docs in Gradleware but I don't get to make my projects compile.
My file structure is like:
+projects
|+libraryProject
|+---workspace
|+------projectSrc
|
|+project0
|+---workspace
|+------projectSrc0
|
|+project1
|+---workspace
|+------projectSrc1
.
.
|+projectN
|+---workspace
|+------projectSrcN
Each project contains docs, design files, etc... and therefore is no convenient to have the src in the same root folder.
In my "project1", settings.gradle file I've used:
include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')
In my build.gradle file, dependencies section I add:
dependencies {
compile project(':..:..:..:libraryProject:workspace:projectSrc')
....
}
But I get an error saying that the project wasn't found.
I've also used the following approach:
def customLib = file('../../../libraryProject/workspace/projectSrc')
settings.createProjectDescriptor(rootProjectDescriptor, 'module-custom-lib', customLib)
include ':module-custom-lib'
Then in the build.gradle
dependencies {
compile project(':module-custom-lib')
....
}
Please help. Thanks for your time.
EDIT: I've managed to get it working by adding the module app as a suffix in the project dir.:
include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc/app')
Now the library members resolve perfectly, but the project's 'R' resource class can not be resolved. So if I do:
setContentView(R.layout.main);
it fails to find that resource. Cleaning and rebuilding the project doesn't fixes the issue.
EDIT 2: Apparently, there was a problem with the manifest merging 'cause the problem was fixed once I adjusted the minSdk and targetSdk of both projects. The previous solution work perfectly.
Your first attempt has a simpler syntax, and should work. Your settings.gradle file looks okay:
include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')
though you should be cautious about including a relative path there -- Android Studio may not use the same working directory as a build you do from the command line, so referencing things relative to rootDir may help alleviate problems.
In the dependencies block of a module's build file, you need to reference a module the same way you do in settings.gradle, so you'd use something like this:
dependencies {
compile project(':module-custom-lib')
}
In dependencies blocks, you're linking to projects using Gradle's project namespace, and since you've already explicitly set up the root directory of the library module, you don't need to try to locate it in the filesystem here. That :..:..:.. syntax wouldn't work anyway to reference a module that's outside of your project's root directory, as this one is.
You should consider bundling "releases" of your library to a Maven repository (possibly your local Maven repo). This way you can reference your library from any other project that needs to use it just like you do with 3rd party libraries.
I know that there are different solutions with different libraries posted. But, could anyone help me with this one?
I've busting my head for the past couple of days, and I really don't know what to do. I already tried importing the modules in all the suggested ways from different posts. (Project Structure --> Dependencies --> Add dependencies), etc. My project does not show any errors, but when I run it, it throws me a compilation error that complains about some classes missing. The library only depends on the ViewPagerIndicator's library which I also imported.
here is a picture. Thanks!!!
NOTE:I also have tried it with Eclipse, but the problem is different there. The app crashes when I run it. When I uncheck isLibrary from Properties -> Android and erase those libraries, the app works.
Inspired by this answer, these are the steps I did:
Put the jar file (in my case, 'xxx.jar') into the libs folder of your project
Right click it and select Add as library
Type this in the dependencies part of build.gradle file: compile files('libs/xxx.jar')
Do a clean build. It can be done inside the android studio, but I also ran the gradlew.bat included inside the project folder
Now, the project should be built and run just fine.
You are referencing the library wrong. You need to add the dependency in the build.gradle file. I recommend you to read the documentation first. It's a long read, but totally worth it.
I noticed that a user uploaded the library as .aar file in his maven repo. You might want to use the library from his repo. The setup is very easy (you only need to include the dependency of the better picker library).
I need to use a library project in my project.
But for some reasons a
referenced XML prefix is not recognized.
Here are the steps I did to add the library project:
Project -> properties -> Android -> added the library project
in my project created a folder lib_src -> Build Path -> Configure Build Path -> Link Source (to the src folder of the library project)
But the problem is that a used XML reference to the linked library project is not being recognized.
Please help - what did I do wrong when trying to use this library project?
this is the xml file portion in my project with the unrecognized reference:
<org.taptwo.android.widget.CircleFlowIndicator
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/viewflowindic"
android:layout_gravity="center_horizontal"
app:inactiveType="fill"
app:fadeOut="1000" />
where <org.taptwo.android.widget.CircleFlowIndicator causes the problem.
However I have a linked library folder lib_src with the sub-folder:
org.taptwo.android.widget and the contained class file CircleFlowIndicator.java in my project.
I also have exactly this folder added to my build path.
Please give some advice what could be the reason that I keep getting the problem:
Error parsing XML: unbound prefix at <org.taptwo.android.widget.CircleFlowIndicator
Many thanks!
I'm not sure that your second step of manually selecting a source folder is necessary.
I think the point of the library referencing in the project's properties is to sort it out for you automatically. Try following the steps exactly as they are here:
http://developer.android.com/guide/developing/projects/projects-eclipse.html
Perhaps a clean and build in Eclipse of all the projects involved might help if your settings are correct.
(Also, you didn't mention selecting 'is library' in the library project's properties, so make sure that's done if you haven't already done it)