Can't import Cardboard SDK - android-studio

There is a problem with importing Cardboard SDK to my project.
I downloaded cardboard-java Github repository
then copied the files from it's library to my project's library folder and added the following dependencies:
compile project(':libraries-common')
compile project(':libraries-commonwidget')
compile project(':libraries-videowidget')
But it gives error saying:
Project with path ':libraries-common' could not be found in project
':app'.
Please help me to understand what I'm doing wrong, and tell me if there is another way of importing the SDK.
Thanks

The project syntax is used to describe a dependency on a separate subproject of your root Gradle project. Note that the example repository is aware of all the library subprojects. You probably need to update your own settings.gradle to similarly be aware of the library subprojects you have copied into your Android Studio project.
Alternatively, start over and make sure you follow every step from this Getting Started guide. In particular, using the New module import method should automatically update your settings.gradle file as you go:
First, grab all the required .AAR files from the libraries folder of the sdk. To determine which .AARs you need to depend on, you can examine the build.gradle files of the various sample apps. For example, samples/treasurehunt/build.gradle's dependency section has the following entries:
dependencies {
compile project(':libraries-audio')
compile project(':libraries-common')
compile project(':libraries-core')
}
This indicates that an application similar to the Treasure Hunt sample needs the audio, common, and core libraries.
Create new modules for each of these libraries. Using Android Studio's GUI, this can be done via File -> New -> New Module.... Select Import .JAR/.AAR Package. Locate one of the .AARs and import it.
Then add this new module as a dependency to your main app via File -> Project Structure -> Modules (on the left side's section list) -> YOUR APP's MODULE NAME -> Dependencies (on the right side's tab list) -> '+' -> Module Dependency.

Related

composite builds broken on android or did I do this wrong?

In 10 minutes, I created an empty android library and an empty android application in this git repository
https://github.com/deanhiller/compositeAndroid
As seen in my last commit, I quickly convert the android application do depend on the library via gradle's awesome composite build feature (We use this feature a TON in our monorepo so loading a project loads all the libraries source code that it uses as well). Our library is shared amongst a few projects.
I cd into compositeAndroid/MyApplication and run ./gradlew build and it fails with
* What went wrong:
Could not determine the dependencies of task ':app:mergeReleaseAssets'.
> Could not resolve all task dependencies for configuration ':app:releaseRuntimeClasspath'.
> Could not resolve com.tray.android:MyLib.
Required by:
project :app
> No matching configuration of project :MyLib was found. The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.1.0' but:
- None of the consumable configurations have attributes.
I am not sure how to work around this. I have a work around to publish/consume but would much prefer composite builds as it brings the source of libraries into intellij cleanly.
Why is composite builds not working? Is there something special I have to do for android projects? The above repo I setup in 10 minutes with those 2 projects(brand new).
You can always clone and play with it yourself as well. (We will actually be releasing our monorepo open-source template however it is not working to well with android just yet).
After looking into the code under MyLib folder in the repository you shared here - it seems you've opened a regular project and intend to use it as a library
Can you please follow the steps required here and test it under a new module?
Hint: your build should result with an aar file

How to import an Android library aar as a module with Android Studio Arctic Fox?

I used to be able to import library aar files as modules and they have been working perfectly. I cannot figure out how to do it with Android Studio Arctic Fox, its latest version. Could anyone offer a tip on it?
I can follow the official instructions to add an aar as a dependency by adding the following in build.gradle:
implementation files('libs/myLibrary-release.aar')
Unfortunately, this will require the dependent app (i.e., the app that uses the above line in its build.gradle to use the library) to know which external libraries are used by myLibrary and add all the dependencies too. For example, if myLibrary has 30 dependencies such as "implementation 'joda-time:joda-time:2.10.5'", every dependent app will have to have these 30 dependencies. If myLibrary updates with a new dependency, all the dependent apps will need to add it too. The worst thing is the app can build and start fine without these dependencies but will crash at runtime when a missing dependency is needed.
I recommend embedding all of myLibrary‘s dependencies inside myLibrary’s AAR file.
Embedding is quite easy - download all of the AARs and JARs of all of myLibrary’s dependencies, save them in lib folder and add the new local dependencies in the form of:
implementation files('libs/some-dependency.jar')
You do need to worry about duplicate class definitions in the app that consumes your AAR.
For example, if you usejoda-time library and your consumer also use joda-time, the consumer’s build will fail because joda-time library is compiled twice.
The solution is to shadow your dependencies by changing all classes’ class path to a unique class path which cannot collide with you consumer app’s dependencies.
For example, class org.joda.time.DateTime will be transformed to just.a.unique.prefix.org.joda.time.DateTime.
I’ve seen shadowing in action, but I’m lack of experience with it.
But check out the following guide to help you out:
https://imperceptiblethoughts.com/shadow/

KMM how to import the generated Greeting class in my current project?

I've added a KMM module in my Android Studio project.
My project builds successfully.
Now to test everything I'm trying to use the auto-created Greeting class in my main project, but autocompletion does not suggests the class.
Am I missing something? Do I need to add something to my gradle file?
Thanks!
If you have just created a new project with KMM Application Template then you might have already got the simple example where Greeting is already imported in the project.
Although if you are not able to import in any case then please check if you have added shared module in your dependencies of App level build.gradle.kts it looks like this :- implementation(project(":shared"))
and then you need to import is as
your shared package name.Greeting for example :- import com.example.kmmsample.shared.Greeting you can get your shared package name in manifest file for shared module it should be named as androidMain\AndroidManifest.xml
Now in iOS you can simply add it as import shared if you have already added it in your Framework.

Setting up a modular project in Android Studio

I'm coming from the Visual Studio world of solutions, where each solution can consist of multiple projects that can refer to each other.
What I want to do is create a modular Android project in Android Studio such that all my code doesn't live in one huge app project. However, it seems terribly difficult to do this, so much so that I am sure I am doing something wrong.
I created a blank project called MyProject. This creates a project with the name MyProject and a package com.sohum.myproject. There is a single app project contained within containing no source files.
I now want to add another module under the same namespace (e.g. com.sohum.myproject.library1). However, it seems when I try to add a new module via the menu, I can only do so into a com.sohum.library1 project. How do I get it to use the same package as the project?
My end goal is to have all my modules under the com.sohum.myproject package, referencing each other. For example:
com.sohum.myproject.application will be the entry point. It might depend on com.sohum.myproject.library1 and com.sohum.myproject.someotherlibrary. And I would like to see all of these modules when I open the MyProject file.
You can click File > New > New Module. Then choose Android Library and enter the details.
Reference: https://developer.android.com/studio/projects/android-library
Another way is to set up the project in a subpackage when creating it.
For example, create a project MyProject in a root directory. Call the application Application and rename the package to be com.sohum.myproject.app instead of just com.sohum.myproject. Now any new modules created will be added below the com.sohum.myproject package space.

How to import existing node.js module into Intellij IDEA?

I have an existing Node.js codebase, forked from GitHub. Now I want to import it to the Intellij IDEA 13 (ultimate version, which supports Node.js). When I simply try to import the project from the root folder of my existing code, IDEA doesn't add the 'lib' folder, where all the sources are. It should be simple, but I cannot figure it out. Any hints?
Well, I've figured out a workaround, but not sure if it's the best solution. One can just create a new project of type "Web", and point it to the directory containing the module's sources. Then IDEA understands the whole structure, and you can create run configurations with Node.js.
In order to get additional Node features, like Intellisense for standard Node APIs, you'll still want to configure the project to be a Node project:
Open the Preferences window
Click Languages & Frameworks → Node.js and NPM
In the section Coding Assistance you'll see if Node.js Core library is [not] enabled. If it is enabled, there's nothing more to do. If not click the Enable button
Leave For the whole project checked, and click Configure
The text should now change to Node.js Core library is enabled.
Another workaround:
If you have a version controlled Node app with no local changes, you could also create a new project of type "Node.js and NPM", point that to the directory. Then just use any standard settings.
After the project is created, you can just revert the files overwritten by IDEA (e.g. app.js and package.json), delete any new directories and files, and you will get the additional Node features in your project.
Intellij 15 Professional Edition:
Import a new project -> Select the base folder of the project -> choose import form existing source.
When Intellij is done it wont look correct so do the following:
1) Project Structure CMD + ;
2) Go to Modules
3) Add a new module and select Node/Npm (if you dont have it then add a new plugin)
4) Point the source of the project to the base folder and click apply.

Resources