How to change default dependencies implementations when starting new projects - android

When I create a new project the activity_main.xml file does not show the default "Hello World!" TextView. I found a video which corrected this by changing an "implementation" line in the build.gradle (Module:app) file. He changed the end of the second implementation line from beta01 to alpha1.
`dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}`
I suspect that some setting is off, either in the way I configure new projects to build, or some other possibility I'm completely unaware of. Is there a way to change what defaults under dependencies on a new project build? I'm not certain if this is the cause of the problem, or the symptom of a larger one. I cannot seem to follow the simplest of tutorials three steps in before getting errors which seem simple, but I cannot seem to resolve.
I'm new to Android and have some experience coding. I'm quite lost, however, because I can't seem to follow alongside simple tutorials. Any help would be great.
I'm using Android Studio 3.1.4
The video I reference (near 45s to 1m in): https://www.youtube.com/watch?v=dpGqlBDqz_M&t=80s
I've also checked out the Gradle doc's to no avail: https://docs.gradle.org/current/userguide/declaring_dependencies.html

Related

Android Studio Javadoc won't generate because "Selected scope contain no Java classes"

I am trying to generate the JavaDoc for the Activity class source code in Android Studio 3.6.3. The file is open in the editor, and I use "Tools | Generate JavaDoc".
When I click OK, it fails with the message "Error running 'Javadoc': Selected scope contain no Java classes". I also tried the "Custom Scope" option with "Current File" choice, but same results.
Can someone help why can I not generate the JavaDoc for this file?
The file is too large to paste here, it is 410832 characters, only 30000 allowed.
I could paste some of it if that would help.
I think maybe JavaDocs needs compiled code with no errors, missing references, etc. When I open Activity.java, It is not compilable.
Thanks for the idea. It was someone else's code, so I looked at another project of mine where the build.gradle file for the module has:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Then I followed the declaration chain in my code for an Activity up to the Activity superclass -- and it goes to the same source file. I guess my SDK has one source file regardless of the library used. Anyway, same problem, it won't print the JavaDoc. I don't understand why it won't print that source file, since it exists.

error: package android.support.v7.widget does not exist

I'm trying to use an SDK given with the RFID scanner I recently bought.
I'm trying to run the sample code given, but it won't compile. I get the following errors on compilation:
error: package android.support.v7.widget does not exist
error: package RecyclerView does not exist
I've tried all the solutions on similar posts, and I'm pretty sure I have the support library correctly installed.
Here are all my dependencies in my build.gradle (app)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.material:material:1.1.0-alpha08'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
implementation project(':Rfid.AsciiProtocol-Library')
implementation 'com.android.support:appcompat-v7:+'
implementation 'com.android.support:recyclerview-v7:26.0.0'
}
I'm new to Android Studio, and as I said I tried pretty much all the answers for similar problems and nothing works. Any help welcome :)
Thanks a lot in advance,
Cyril
You should replace android support recyclerview with androidx
implementation 'androidx.recyclerview:recyclerview:1.0.0'
And you can delete 'com.android.support:appcompat-v7:+' dependency, because you've already import it with
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
It frustrated me for literally hours because the answer here given is missing so much.
In dependencies of gradle:
import:
implementation 'androidx.recyclerview:recyclerview:1.0.0'
click gradle sync (should be a bar on top of the page that pops up
Then in your java file where u actually use the RecyclerView class, import this:
import androidx.recyclerview.widget.RecyclerView;
and you are done
EDIT: So apprently you just need to auto-fill the object you need and android studio will auto inport for you. example:
try to type recyclerview, but press tab to auto-fill it. The object should automatically be imported for you on top of the java page. This works with all android studio objects like view and intent.

How to fix appcompat gradle error? android 3.4

Having continuous problems with my gradle. The
implementation 'com.android.support:appcompat-v7:28.0.0'
is underlined in red
This is stopping me from continuing in my development (i'm still very new to android). My problem initially started with
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
being underline in red and causing an error, but changing my import to
import androidx.fragment.app.FragmentActivity;
cured the problem, but my gradle still is having build problems. I have android 3.4, and my gradle wrapper is 5.1.1. I have no idea how to stop the error from occurring and getting rid of my gradle errors.
I've changed it to alpha1, rc01 and tried downgrading the version but its not working.
The dependencies is where my problem is occuring:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha7'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I just want the gradle to full work and be able to move on haha, I've been trying to fix this for a while...
You are still using older support libraries hence the errors persist even in the app level Gradle file. Add these to your Gradle:
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
After replacing these with your current implementations in your Gradle, sync the project. After that, clean/rebuild the cache.
Now the code you have wrote is most likely going to give error because the code was using older support library which is no longer in your project. To solve it, you need to rewrite the error code but this time using androidx imports.
You need to refactor your project to androidx
Go to Refactor -> Migrate to androidx
Click on Migrate

Android: Program type already present: com.google.zxing.BarcodeFormat

I've develop a project using zxing to scan the barcode. I had followed the tutorial from here, but unfortunately I got error when I tried to run the project to device. The error that I get is
This is the build.gradle(app)
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// volley
compile 'com.android.volley:volley:1.0.0'
// butter knife
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
// picasso
implementation 'com.squareup.picasso:picasso:2.71828'
// QR Zxing Library
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
}
Below is External Libraries list.
After a day I tried to find out the solution, but everything failed. Then I decided to create a new project and copy the current source code together with build.gradle(app). Luckily no more error occurred when I run new project.
But I still don't know what the actual reason why I got that error before this, so I assume maybe some part of the old project are missing or have some bug on it.
Because at new project you change buildToolVersion
Reason : Its happened because being conflict between core.jar and zxing
Solution : Just change buildToolVersion and build , after that revert old toolVersion and build again !
After weeks of searching, the following steps help me resolve the issue like a charm:
1.Remove android platform.
2.Install cordova-plugin-facebook4
3.Create build.gradle in /plugins/cordova-plugin-facebook4/
4.Copy this
dependencies {
compile("com.facebook.android:facebook-android-sdk:4.37.0") {
exclude group: 'com.google.zxing'
}
}
to ../plugins/cordova-plugin-facebook4/build.gradle
5.Edit ../plugins/cordova-plugin-facebook4/plugins.xml change
to
6.Add platform android and build

Updating External Libraries in Android Studio

I'm fairly new to Android development, so apologies if this is obvious. I've searched quite a lot but am unable to resolve my issue.
In my build.gradle file I have the following section:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-auth:15.1.0'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.wdullaer:materialdatetimepicker:3.2.2'
}
However the line implementation 'com.android.support:appcompat-v7:26.1.0' is showing with a red squiggly line underneath and displaying the following message:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 26.1.0, 25.3.1. Examples include com.android.support:animated-vector-drawable:26.1.0 and com.android.support:support-v13:25.3.1 less... (⌘F1)
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).
I am unable to find out how to solve this issue. Building the project works fine and does not report any errors. I've tried doing File > Invalidate Caches / Restart but to no avail.
After doing a bit of searching I read that I can add implementation 'com.android.support:support-v4:26.1.0' to the build.gradle file and it should fix it, however the same error shows even after syncing.
This is an old project I made sometime last year and it doesn't have a lot in it, but I thought it would be better to learn how to resolve this issue rather than just creating a new project to get around it.
Try adding
implementation 'com.android.support:support-v13:26.1.0'
Although in your question, error is explaining everything, com.android.support:animated-vector-drawable:26.1.0 and com.android.support:support-v13:25.3.1 are not having same version.
Should always keep support libraries version same in build.grdale.
implementation "com.android.support:appcompat-v7:$support_lib_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation "com.android.support:design:$support_lib_version"
implementation "com.android.support:support-v4:$support_lib_version"
implementation "com.android.support:cardview-v7:$support_lib_version"
implementation "com.android.support:recyclerview-v7:$support_lib_version"
where support_lib_version is a constant.
ext { support_lib_version = '26.1.0'}
in same build.gradle file out side 'android' and 'dependencies'.

Categories

Resources