I want to add a native (integration test) module to a Cordova Android project.
For fully native projects, you just add a new module, commit and be done with it. But for Cordova I of course don't really want to mess with the generated Android project as some of these changes might be lost on build etc.
I got a Poof of Concept of the module working manually by having the module folder outside of the Cordova Android folder and adding this to settings.gradle:
include ':module-androidTest'
project(':module-androidTest').projectDir = new File("../module-tests")
But of course line 1 of that file already says
// GENERATED FILE - DO NOT EDIT
Is there any other way to add additional modules to a Cordova Android project?
Some approaches I researched or thought about:
Can I somehow do this with build-extras.gradle? (I don't think so as settings.gradle is several steps before build-extras and build.gradle, right?)
Older StackOverflow questions suggest manually editing a GradleBuilder.js file: https://stackoverflow.com/a/35504783/252627 But of course this would get lost each time I completely generate a new Cordova project. Not a good idea, correct?
Can I maybe work around this somehow via a Cordova plugin? I know these can load frameworks etc - maybe also a module somehow?
I think what you are looking for can be done using a custom plugin which can extend the base gradle config using a framework tag like this:
<framework src="relative/path/to/your/gradlefile/*.gradle" custom="true" type="gradleReference" />
This is how a cordova-android project is usually extended.
Related
Since Unity 2019.3 the Android build process has changed and now the gradle project contains two modules - a unityLibrary module and launcher module.
I am having trouble uploading native symbols as I cannot apply the plugin to the unityLibrary module, and only works in the launcher. Is there a certain way I can achieve this?
When I run uploadCrashlyticsSymbolFileRelease task that is only present on the launcher module, I receive this error:
Could not find the file generated by Google Services. Please check your Firebase project configuration
The configuration file is in the unityLibrary module.
Is there any way to move the task to the unityLibrary module? If I move the crashlytics plugin to the unityLibray module the error changes into:
Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
The tricky bit is that Firebase is still compatible with versions of Unity that do not support gradle integration. Because of this, the build pipeline in Unity re-implements the functionality of the google services plugin (namely generating the values.xml file).
I've personally put some effort into massaging the mainTemplate.gradle file to work with gradle plugin, but haven't gotten the NDK upload to work yet. Some notes that may help:
The External Dependency Manager for Unity (EDM4U) will both update the mainTemplate.gradle file if available but will also process google-services.json and drop the output into Assets/Plugins/Android. You'll likely want to run it once to generate the dependencies, delete the values.xml, and then disable EDM4U to prevent it from regenerating that file.
The Unity SDK is based on C++, and the aar archives that bind C#, C++, and Java are packaged into local maven repository in your Assets directory. This will make it hard to relocate your project after generating it (ie: try to do all your work Unity side if possible).
Because you'd be short-circuiting Firebase's processing of values.xml to use the plugin, you'll need to make sure google-services.json actually makes it into your Android sourcetree. Assets/StreamingAssets might do this automatically but you may have to write a build script to copy it over.
Finally, the team is aware of the desire to debug NDK code in the Unity Crashlytics plugin. There aren't any public timelines available, but in lieu of a good answer opening an issue on the quickstart or posting to the mailing list might could be a good way to try to work through the process.
I am very new to Mobile Development especially with the use of Android Studio and Java (but i'm familiar with the language already as i came from C#). But the challenge is i don't yet how to configure the project itself unlike what i can do in VS.
Basically i am trying to include a downloaded SDK, the package looked like it is the same as my project (contains Gradle, etc, etc, so i've thought this is Gradle Project).
What i have tried
is going to file -> Project Structure -> Dependencies -> Add Dependency. Which is basically including a Gradle Project from the options.
It went a-okay but i'm not aware yet it this was right? I checked the Docs from android studio and included the dependency in my Gradle.
It goes like this: implementation project(":MyDownloadedProject")
I know this is pretty simple but i've been checking out stuffs for a long time already but unable to find any useful resource.
Thanks a lot!
Add build dependencies with autolinking or by manually adding to build.gradle
see https://developer.android.com/studio/build/dependencies
I've been trying to use this solution into my android project:
https://github.com/jlhonora/multistatetogglebutton
I tried since several hours, but I only managed to messed up with everything, forcing me to delete everything, reseting android studio, clone my project and restart from scratch.
I tried the solutions explained in android arsenal but it didn't do the trick.
It's all in the README on the git page you linked.
You need to include the following line within the dependencies block of your build.gradle:
compile 'org.honorato.multistatetogglebutton:multistatetogglebutton:0.2.2'
Then you can use the library, once you have sync'd the build.gradle (which it should immediately ask you to do).
I understand this might be an extremely obvious and ridiculous question to ask, but please excuse me as I'm a beginner. I want to integrate this file into my project so I can call its methods:
https://github.com/RomainPiel/Shimmer-android
The question is, what do I do with it? Is it considered a "module", "library" or "file"? Should I manually copy the source files and create new classes in my project, and then call the methods from there? This would be the most straight-forward but in the "how to use" section in that package, it was mentioned "compile 'com.romainpiel.shimmer:library:1.4.0#aar'"
What I tried:
I downloaded the file as a .zip and then File->New->Import Module then navigated to the unzipped file. I believe I'm then supposed to add "compile 'com.romainpiel.shimmer:library:1.4.0#aar'" so I went to the gradle file to try to add it.
There are two: build.gradle (Module:app) and (Project:ProjectName).
I've tried adding to either and\or both and got this error: (Error:9,0) The project 'ProjectName' may be using a version of Gradle that does not contain the method. Did I do something wrong? Is it supposed to be this easy?
I would be extremely grateful to anyone who can point me in the right direction :)
You have three option
Using the GitHub Desktop you can clone the project and open it like a local project. Every change you make will be tracked. You can then commit and push using the GitHub Desktop. It's all UI and simple to use.
https://desktop.github.com
On Android Studio, when you open it, you'll see this, select GitHub and continue by adding your credentials.
You can then commit and push directly from that.
Using the terminal / command line.
If you are new, I recommend the first. It's simple to use and you get a hang of using it as it is the same steps with any project on any IDE you use.
Note: Downloading it as zip and then using it a bad idea because you're making it difficult on yourself because you can't keep track of changes and you'll have to re-upload everything every time. Which defeats the purpose of version control
If that GitHub account is not yours, then you'll have to fork the project, this way you'll have a separate version of the code on you GitHub on which you can modify. If it is yours then you're good.
Typically, you do not want to include external source code manually. This inhibits your build tool's (i.e. Gradle's) ability to manage that source code. It's very easy in Gradle to, say, set the version (like you have done by specifying "1.4.0") and then later remind yourself what version you have by merely looking at your build.gradle file. However, how would you go about doing that with raw source code? Typically developers do NOT put the version number of the source code in the actual source code - that's what they use their version control system (e.g. git) for, usually with tags.
Another aspect of Gradle is downloading and caching (and compiling) the external project for you. So that's nice.
With that said, you typically want to put that "compile..." line in your module's build.gradle file. Not the Project's build.gradle.
A module corresponds to your application (or library) that you are building or using. Some project's have multi-module configurations, where one module acts as a dependency for another (or several others). A Project in gradle is more of a 'meta' configuration that you can apply to all of your modules. The gradle docs recommend you focus on your module's configuration first and adjust the Project's configuration only if you have a specific need and reason to do so.
For the error you mentioned, you might have some unnecessary configurations in your build.gradle file, or the tool version numbers might not reflect what's on your system - if you copied and pasted from the internet, you might want to correct this by letting your IDE generate that file (the brute-force approach would be to create a new project entirely, and use its build.gradle files as a reference). Before you do that, you might want to check if your IDE provides any warnings inside that file.
You have to add the dependency to your module's gradle file.
There are two gradle file present in an android project. One is the project gradle and the second is the module gradle for each individual module.
You just have to copy the given
compile '......' in the dependency block.
This problem seems to come up for a few people, but I haven't been able to apply the solution suggested in other threads for one reason or another so...
I am trying to build a simple android app with an embedded webserver. The server of choice if jetty. I am using maven to manage dependencies with the maven-android-plugin. I have added jetty-server v8.x as a dependency with the default scope. When I try and deploy my apk to the sandbox I get an error
Found duplicate file for APK: about.html
So the file in question is from the jetty package, or rather it is found in two jetty packages, one being a dependency of jetty-server. Other threads out there seem to be suggest I delete the file from one jar or the other but this is not really a scalable solution as I am not the owner of the jars.
Is there a more general solution to this problem? Something that manages the conflict and build or deploy time?
I should note, I am a bit of a Java noob, and have gone the NetBeans and maven route because this is the toolkit I'm familiar with.
OK, found it. The solution is to build using the following command
mvn android:deploy -Dandroid.extractDuplicates=true
There are a couple of issues:
First, to integrate Jetty, your project is going to need a pom.xml file. The Android APK (as-is) does not know how to resolve a pom with Maven dependencies without some sort of bridge. So, you'll need to install a few plugins for Pom management onto Eclipse. Follow the instructions here: http://rgladwell.github.com/m2e-android/
(I found it easier to create a new project using the method described here rather than converting my existing Android app to a Maven project, but I'm sure it'll work either way.)
Second, once you've installed this, you're going to have to make sure your pom.xml contains the necessary dependencies, build goals, and variables. So, open up your pom.xml, and make sure you have the following:
In the "build" node:
sourceDirectory -> src
defaultGoal -> install (I suppose...)
In the "dependencies" node:
... all the jetty/cometd dependencies (org.cometd.java, org.eclipse.jetty, etc.)
Third, you should know that you can't just click the green run button and launch the app via ADB. You have to install it the maven way (Run As -> Maven build/install/test/whatever)
You should open up your war file and check if you actually have two about.html files in there. Some time ago I had two web.xmls in my war files. If you actually have duplicates then you should try to exclude those files.
Maybe you have one file in your project and the duplicate is generated by the maven plugin.
I also just realized that you're probably already properly using the android-maven plugin. One other important tip: change the scope to runtime on the jetty dependencies. This builds successfully for me, whereas using the default scope (compile) always threw the duplicate file in APK error.