Android Studio: Are Library Project dependencies picked from project.properties? - android

I have imported my project from ADT and after going to "Module Settings" and editing dependencies things are working fine.
My "build.gradle" has dependencies block empty, So I am wondering from where is Ansdroid-Studio picking libraries dependencies ? As I migrated from eclipse so I have project.properties file in module directory. Does Android-studio pick these things from "project.properties" file ?

Android Studio's default project support is done through Gradle, unless you have an Android project coming from IntelliJ which you can open with Studio as well.
If you use Gradle, project.properties is completely ignored. You should not use the Module Settings to add dependencies now as it only changes the IDE but not the Gradle based build system (we'll fix this in later versions).
If you have missing dependencies in your build.gradle, it may be due to a bug in the export from ADT. We have fixes for this coming soon.

Probably not, since a new project on Android Studio does not generate a project.properties file.
Presumably in Android Studio that is not where dependencies are coming from, but I can't be too sure.

Related

Android Studio analyzing infinity

I have a problem: My android studio is analyzing infinitely:
I have tried:
uninstalling Android Studio
Invalidate cashes / Restart
restart my computer.
build.gradle (Project)
build.gradle (Module)
Main Activity (Analyzing text top right corner)
What can I do?
You just need to Upgrade the latest kotlin version.
Upgrade the dependency in the project's build.gradle file.
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
Upgrade the dependency in the app's build.gradle file.
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.10"
Finally, I fully deleted my android studio with all connected files using this answers and then reinstalled its new stable (the same 4.2.1. version). The problem was solved.
I was also facing the same issues.
I Follow below step:
Close Project
Delete all “.idea” & ".gradle” folder
Want to solve this problem, you need to download the kotlin plugin with the version 202-1.5.0-release-764-AS8194.7 at this website https://plugins.jetbrains.com/plugin/6954-kotlin/versions, then install it.

Android Studio generates R file only for modules with no module dependencies in multi-module project

After updating to AS 3.3.1 from 3.2.something I've got a strange bug: R file is generated only for modules that do not implement any other modules. I still can compile project or go to declaration via cmd+B, but every resource file like R.layout.activity_main is highlited with an "unresolved reference" message, until I remove every module implementation from module build.gradle and resync the project.
As far as I've noticed, the problem does not related with android gradle 3.3.0 or kotlin 1.3, since my old projects are affected as well.
What I've already tried:
Clean/Rebuild project
Invalidate cache
Resync Gradle
Switch to Android Gradle 3.2.1
delete .idea directory
Here's my project, module build.gradle example and used libraries.
For example, if I comment implementation(project(":presentation")) line in mainscreen/build.gradle.kts, the error disappears. Obviously, it isn't the solution.
UPD: SOLVED
Solution: you have to specify different package names in each AndroidManifest.xml files, i.e. com.mycompany.example.launcher for launcher module, com.mycompany.example.presentation for presentation module et cetera.
[solution1]
You can delete the old version of gradle from your system and start installing its new version.
[solution2]
Or remove Android Studio and reinstall it

Unable to find module with Gradle path. Linking to library -unspecified instead

Update 2 This has been fixed in Android Studio 1.2 Beta 3
Update: This has reportedly been fixed in an upcoming release of Android Studio.
In Android Studio 1.2 Beta 2 I started getting the following warnings when syncing Gradle.
Failed to set up dependencies
Warning:Unable to find module with Gradle path ':Library1'. Linking to library 'Library1-unspecified' instead.
Warning:Unable to find module with Gradle path ':Library2'. Linking to library 'Library2-unspecified' instead.
I've noticed that jumping to a declaration declared in one of the library modules pulls up the Decompiler instead of just going to the actual source in the library module.
In my Android Studio Project I have the following modules:
- App
- Library1
- Library2
Module: App build.gradle snippet:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Library1')
compile project(':Library2')
}
settings.gradle file:
include ':App'
include ':Library1'
include ':Library2'
project(':Library1').projectDir = new File(settingsDir, '../library1/lib')
project(':Library2').projectDir = new File(settingsDir, '../Library2/lib')
I faced this with Android Studio 2.2.3. The problem was with the .iml file that was causing the problem.
After importing the module folder into the project directory and adding the changes to include module in settings.gradle, delete the .iml file from the module folder and do a Gradle Sync. Then right click on any module in the Project Window and click on "Configure Project Subset...", if the imported module is not checked, check it and Android Studio should do a Gradle Sync. By then the imported module will appear in the Project Window and will have a .iml file regenerated that is does not cause any issues.
delete the .iml file under the error module.
restart Android studio
Right click project, Select "Configure Project Subset ..." and select your module, rebuild your project.
I met the same problem on AS 2.0 preview,
and I fixed it by following steps:
1.Rename the module.
2.Change the names in app/build.gradle and setting.gradle.
3.Start gradle sync.
I don't know why but it works on my issue.
Check in settings. of your app.
Down there is the field "Load/Unload Modules"
Your module might be unloaded, that's why Android Studio ignores it even if you specify it in Gradle.
At least that was the problem for me.
If you are using React-native>60, then you should run npx jetify on root of your project before doing Gradle sync.
For me the following worked in Android Studio 3.5.3
First of all, check if the path is correct in your Gradle settings.
If the path is correct then invalidate caches & restart by navigating to the top 'File' menu
It is a known bug introduced in 1.2 Beta 2.
See This issue on the Android issue tracker. Fix should be out within hours.
I had this problem and solved it by clicking on
File> Ivalidate cache / Restart...
as shown below:
Problem:
This problem can also occur when you change the path to the module.
settings.gradle
include ':app', ':filechooserlibrary'
project(':filechooserlibrary').projectDir = new File('../../repos-github/file-chooser/file-chooser-library/filechooserlibrary')
I changed the path to '../../github/file-chooser/file-chooser-library/filechooserlibrary'
The old path did not exist any more. But then, instead of accepting the new path, Android Studio recreated the old path structure thus referring to an empty directory.
Solution:
So, I deleted this obsolete path structure and restarted Android Studio, after deleting the .iml file (I don't know if this is necessary, but it cannot do harm). Then I reimported the Gradle project and it worked.
Try using an updated version of NDK.
I faced the same issue.
I was using NDK version r17c. Issue solve after using r21e.
Android Studio Version: 4.1.3
OS: Ubuntu 18.04.5

java.lang.NoClassDefFoundError: butterknife.ButterKnife

I've recently started doing Android development again and I am not yet used to the new gradle build system. Any dependency I add (so far I've tried Joda DateTime and butterknife), it always throws an error NoClassDefFoundError.
Here is what I've done. I'm using IntelliJ.
build.gradle:
compile 'joda-time:joda-time:2.1'
compile 'com.jakewharton:butterknife:4.0.1'
File > Project Structure > Modules > MyModule > Dependencies > Add Library, download from Maven, click export and bump it up the list.
My dependency list now includes a maven module com.jakewharton:butterknife:4.0.1
What am I doing wrong here? My IDE resolves everything fine, but at runtime none of the classes can be resolved.
Side note: My BUILD would not even complete until I added the above line to build.gradle. So I have to add the dependencies in Project > Project Structure AND to the build.gradle?
Also my project structure is:
UITest (parent)
UIBeta (android application)
UILib (android module)
I see the butterknife lib in the UITest\libs folder, shouldn't the children be able to find this?
Well I was going to delete this but maybe it will help someone else:
My gradle clean was broken because some aar was locked and it could not delete it, I had to close out IntelliJ, rename the aar (appcompat7 I think it was), then restart. I might not even have had to rename the file as I'm guessing the lock was released upon closing.
After restarting my clean worked, upon next run no more error.

How to add Android Support Repository to Android Studio?

I'm using Android Studio with an external Android SDK. I have installed the support library and the support repository. The support repository is in:
~/Development/Tools/android/sdk/extras/android/m2repository
When I add a dependency to the support library in the build.gradle file, like:
...
repositories {
mavenCentral()
}
...
dependencies {
compile "com.android.support:support-v4:18.0.+"
}
Android Studio cannot find the support libraries (cannot resolve symbol etc) and Gradle also cannot find the libraries:
Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
> Could not find any version that matches com.android.support:support-v4:18.0.+.
Required by:
TestAndroidStudio:TestAndroidStudio:unspecified
How do I specify in Android Studio and/or the build.gradle file the location of the Android support repository?
You are probably hit by this bug which prevents the Android Gradle Plugin from automatically adding the "Android Support Repository" to the list of Gradle repositories. The work-around, as mentioned in the bug report, is to explicitly add the m2repository directory as a local Maven directory in the top-level build.gradle file as follows:
allprojects {
repositories {
// Work around https://code.google.com/p/android/issues/detail?id=69270.
def androidHome = System.getenv("ANDROID_HOME")
maven {
url "$androidHome/extras/android/m2repository/"
}
}
}
Gradle can work with the 18.0.+ notation, it however now depends on the new support repository which is now bundled with the SDK.
Open the SDK manager and immediately under Extras the first option is "Android Support Repository" and install it
Found a solution.
1) Go to where your SDK is located that android studio/eclipse is using.
If you are using Android studio, go to extras\android\m2repository\com\android\support\.
If you are using eclipse, go to \extras\android\support\
2) See what folders you have, for me I had gridlayout-v7, support-v4 and support-v13.
3) click into support-v4 and see what number the following folder is, mine was named 13.0
Since you are using "com.android.support:support-v4:18.0.+", change this to reflect what version you have, for example I have support-v4 so first part v4 stays the same. Since the next path is 13.0, change your 18.0 to:
"com.android.support:support-v4:13.0.+"
This worked for me, hope it helps!
Update:
I noticed I had android studio set up with the wrong SDK which is why originally had difficulty updating! The path should be C:\Users\Username\AppData\Local\Android\android-sdk\extras\
Also note, if your SDK is up to date, the code will be:
"com.android.support:support-v4:19.0.+"
Android Studio 3
Make sure you have the latest version of Android Studio. The support library is included by default when you create new projects. If you are adding the Support Library to a project that doesn't have it, then you just need to add a single line to your app module's build.gradle file, and then sync gradle.
build.gradle
dependencies {
...
implementation 'com.android.support:appcompat-v7:27.1.1'
}
It should just be that easy, though there may be some things to note:
Android Studio should give you a warning nowadays if the support library needs to be updated. Just update the 27.1.1 numbers that I have here to whatever it tells you to. You can also manually check what the latest revision is if you want to.
The implementation keyword replaces compile that was used in Android Studio 2.x. (What's the difference?)
There are other support library packages that you may need to include depending on what your app uses (like constraint-layout or recyclerview).
Make sure that you have the latest updates for everything in the SDK Manager. Go to Tools > SDK Manager.
Documentation
Support Library
Support Library Setup
Support Library Features
I used to get similar issues. Even after installing the support repository, the build used to fail.
Basically the issues is due to the way the version number of the jar files are specified in the gradle files are specified properly.
For example, in my case i had set it as "compile 'com.android.support:support-v4:21.0.3+'"
On removing "+" the build was sucessful!!
Instead of doing this:
compile "com.android.support:support-v4:18.0.+"
Do this:
compile 'com.android.support:support-v4:18.0.+'
Worked for me

Categories

Resources