How to make netbeans find my class path library - java

I have netbeans 12.4 and java 11 installed on fedora. I have created a Gradle multi project. It compiles fine but code completion isn't working
In Netbeans, have created I library named Facebook in tools>libraries. I then extracted classes.jar from Gradle cache file .aar packages. I renamed and added these to Facebook Library class path
I can't seem to be able to find the class path in my java files when I do
import com.facebook.*;
Netbeans says unable to find class path com.facebook.*;
What am I doing. wrong how can I make netbeans recognize my jar when I am coding like code completion
Project build.gradle
description = 'Example Project'
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.0")
}
}
allprojects {
group = 'com.example'
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Project settings.gradle
rootProject.name = 'example'
include ':app'
Module build.gradle
plugins {
id 'com.android.application'
}
description = 'app'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId("com.example.app")
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":"$projectDir/schemas".toString()]
}
}
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
annotationProcessor 'androidx.room:room-compiler:2.3.0'
implementation 'androidx.annotation:annotation:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core:1.6.0'
implementation 'androidx.fragment:fragment:1.3.6'
implementation 'androidx.lifecycle:lifecycle-livedata:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.3.1'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'androidx.room:room-runtime:2.3.0'
implementation 'com.facebook.android:facebook-android-sdk:5.15.3'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'androidx.room:room-testing:2.3.0'
testImplementation 'junit:junit:4.13.2'
}

In the Projects window right-click on the name of the project that lacks library -> Properties ->
The Project Properties POP UP. In Categories tree select "Libraries" node ->
On the right side of the Project Properties window press "Add JAR/Folder" ->
And here Select jars you need.
You also can see my short Video How-To.

Related

Android Studio Compile Error: Could not find runtime-2.4.0.aar

When trying to run my application on my android device, I get the following error:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find runtime-2.4.0.aar (androidx.lifecycle:lifecycle-runtime:2.4.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/2.4.0/runtime-2.4.0.aar
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
I have tried:
Setting my compileSdkVersion and minSdkVersion to 31
Checking that the library does indeed exist in the maven repository here
My build.gradle (app level)
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.brianokoth.skillsapp"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.google.firebase:firebase-storage:20.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.firebaseui:firebase-ui-firestore:4.1.0'
implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.annotation:annotation:1.3.0'
implementation 'androidx.lifecycle:lifecycle-runtime:2.4.0'
}
My build.gradle (project level)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I look forward to any assistance.
first you could try File -> Sync Project With Gradle Files just to make sure it has been properly imported. Second it's better to add all the life cycle dependencies instead of just one, that's obsolete. so delete the current one and use these one instead:
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha02"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"

Dagger-Hilt Did you forget to apply the Gradle Plugin? But I applied the plugin

Hello I'm trying to use the Dagger Hilt library In my project but when I'm trying to build it, it fails with this message
public final class MyApplication extends android. app.Application {
^
Expected #HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)
See https://dagger.dev/hilt/gradle-setup.html
[Hilt] Processing did not complete. See the error above for details.
And then a java file called MyApplication.java opens with the below content:
package com.example.hilt;
import android.app.Application;
import dagger.hilt.android.HiltAndroidApp;
import kotlin.reflect.KClass;
#kotlin.Metadata(mv = {1, 5, 1}, k = 1, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0007\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002\u00a8\u0006\u0003"}, d2 = {"Lcom/example/hilt/MyApplication;", "Landroid/app/Application;", "()V", "app_debug"})
#dagger.hilt.android.HiltAndroidApp
public final class MyApplication extends android.app.Application {
public MyApplication() {
super();
}
}
this is my project build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.37'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is my app module build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.hilt"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.37"
kapt "com.google.dagger:hilt-android-compiler:2.37"
}
kapt {
correctErrorTypes true
}
as you see I did everything correctly and it still gives me the error. I tested my code on another computer and it worked! I even removed android studio, Gradle, and SDK manager from my computer and reinstall them but it still gives me the error.
How can I fix it?
I finally found the solution. Here you can see an issue related to support for Kotlin's plugin 1.5.20 and as it explains this is the bug of Kotlin's plugin, not dagger hilt's!
The solution is simple, you have to add this code to your build.gradle app module:
kapt {
javacOptions {
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
}
}
Edit:
Just update the Kotlin plugin to the latest version and change ext.kotlin_version to the latest version in project-level build.gradle. The current version is 1.5.21.
Just change the version of this below classpath in your project level gradle to the latest version -
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:VERSION_TO_CHANGE"
I have the same problem on fresh project. And problem was in wrong gradle path.
I specified in local.properties this:
org.gradle.java.home=/Users/cmx/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7935034/Android Studio.app/Contents/jre/Contents/Home
And it helps me.
you did not add annotationProcessor check following link https://dagger.dev/hilt/gradle-setup.html
add like this in your app.gradle
implementation 'com.google.dagger:hilt-android:2.37'
annotationProcessor 'com.google.dagger:hilt-compiler:2.37'

How I can build java module first then the rest of my android application?

In my java project I have the following folders:
app that contains the android specific application
settings_fetcher that is a java module
What I want to do is to build first the java modult create a .jar file then movwe the .jar file into ./app/libs and then build the rest of the application.
The app folder contains the following build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
}
}
plugins {
id 'com.android.application'
}
def versionCodeDate() {
return new Date().format("yyyyMMdd").toInteger()
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "pcmagas.vodafone_fu_h300s"
minSdkVersion 28
targetSdkVersion 30
versionCode versionCodeDate()
versionName "v"+versionCodeDate()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
println 'In release configs'
def keystoreFile = rootProject.file(".keys/h300s.keystore")
def env = System.getenv();
if(env.containsKey('KEYSTORE_FILE')){
keystoreFile = rootProject.file(env.get('KEYSTORE_FILE'))
}
if (keystoreFile.exists() ) {
println("Configuring Signing options for release")
android.signingConfigs["release"].storeFile = keystoreFile
android.signingConfigs["release"].storePassword = System.getenv('MYAPP_RELEASE_STORE_PASSWORD')
android.signingConfigs["release"].keyAlias = System.getenv('KEYALIAS')
android.signingConfigs["release"].keyPassword = System.getenv('MYAPP_RELEASE_KEY_PASSWORD')
}
}
}
buildTypes {
release {
minifyEnabled true
signingConfig = signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests.returnDefaultValues = true
}
}
repositories {
google()
jcenter()
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.activity:activity-ktx:1.2.0'
implementation 'androidx.fragment:fragment:1.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'org.json:json:20210307'
testImplementation 'com.github.gmazzo:okhttp-mock:1.4.1'
testImplementation 'junit:junit:4.+'
testImplementation 'org.mockito:mockito-core:3.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Whilst settings_fetcher contains the following build_gradle:
plugins {
id 'java-library'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
task makeJar(type: Copy) {
from('build/libs/')
into('../app/libs/')
include('settings_fetcher.jar')
}
Any ideas on how I can approach this?
In other words, what I want to do is when I run one of these commands:
gradlew assemble^flavor^
gradlew build
gradlew build^flavor^
Where ^flavor^ is my application's flavor and can be either Debug or Release.
To be able to build the .jar file first and then my app's apk.
In your case the settings_fetcher is a dependency to your app assuming that the settings_fetcher is created as java-library then you can do the following:
In the build.gradle located in app folder place the settings_fetcher project as dependency:
// rest of build.gradle goes here
dependencies{
// Your app's dependencies goes here
implementation project(":settings_fetcher")
}
So once you run ./gradlew build the jar file for your library will be located upon ./settings_fetcher/build/libs folder. Therefore, there's no need for makeJar task as well.
Library Dependencies
Also, any library dependencies should be placed in its own respective build.gradle in your case the one located in settings_fetcher folder in a dependencies section.
For example if your library needs the okHttp client then use:
dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
}
Also in order to use 3rd party libraries ensure that you also have the appropriate repositories as well for example a common repository is the jcenter one:
repositories {
jcenter()
}
Final build.gradle located in settings_fetcher folder
As a result, the final build.gradle will be this one if no extra libraries needed:
plugins {
id 'java-library'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
Or in case you will need some extra dependencies & libraries:
plugins {
id 'java-library'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
dependencies {
// App dependencies go here.
}

Ksoap2 Library to android studio Error message, how to fix?

I an trying to import Ksoap2 library in android studio using .jar file version 3.6.4. I have successfully implemented the jar file to android studio. However, on the module app activity when I try to import e.g. import "org.ksoap2.SoapEnvelope;", it gets and error it shows following results:
Execution failed for task ':app:checkDebugAarMetadata'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.google.code.ksoap2-android:ksoap2-android:3.6.4.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/google/code/ksoap2-android/ksoap2-android/3.6.4/ksoap2-android-3.6.4.pom
- https://dl.google.com/dl/android/maven2/com/google/code/ksoap2-android/ksoap2-android/3.6.4/ksoap2-android-3.6.4.pom
- https://jcenter.bintray.com/com/google/code/ksoap2-android/ksoap2-android/3.6.4/ksoap2-android-3.6.4.pom
Required by:
project :app
Possible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Also the imports library have error, please see the pic:
Here is the Build.gradle module code:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is Build.gradle(app) Module code:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.kowloondairycompanykdl.milk_ic"
minSdkVersion 27
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation files('libs\\ksoap2-android-assembly-3.6.4.jar')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
}
Please help me, I been stuck here for a long time. How to fix the error and how can I implement the Ksoap2 library properly. Thanks
There doesn't seem to be a 3.4.3 version of that library. There's a 3.4.0. And the newest is 3.6.4. You're going to need to use one of those. I'd move to 3.6.4 as 3.4.0 is over 5 years old, and likely lacks security updates.
Remove the dependencyResolutionManagement block from the setting.gradle file to have your project work the old way.
Related issue: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'

im trying to build my app but i getting this error: AAPT2 process unexpectedly exit. Error output

im trying to build my app on android studio but im getting this error
"AAPT2 process unexpectedly exit. Error output"
i search about it and tryed everything to solve this but dosent help me.
android studio version:4.1.1
gradle version: 6.8-rc5
This is my gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is gradle(mudle)
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.weather5"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android- optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
So,finaly someone from Twitter helpd me and solve the problem.
The solution is:
The main cause of the problem is the instability of the android gradle plugin version and gradle version.
You can easily change these versions through the project structcher from the file menu or you can use the command ctrl + alt + shift + S to reach project structur.
My setting is This:
android gradle plugin version: 4.0.1
gradle version: 6.1.1
Be aware that versions SHOULD NOT contain alpha or beta.
Also you can use this link to finde out Which gradle plugin and gradle vesrion are Suitable for each other

Categories