You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to use import androidx.appcompat.widget.Toolbar into a java file when using AndroidJavaSource #8191
Severity Code Description Project File Line Suppression State
Error JAVAC0000 error: package androidx.appcompat.widget does not exist
import androidx.appcompat.widget.Toolbar;
MSBuild version 17.7.0-preview-23251-02+59879b095 for .NET
Determining projects to restore...
Restored /Users/moljac/Downloads/12063900/AndroidApp5/AndroidApp5.csproj (in 686 ms).
/usr/local/share/dotnet/sdk/8.0.100-preview.4.23260.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/Users/moljac/Downloads/12063900/AndroidApp5/AndroidApp5.csproj]
/Users/moljac/Downloads/12063900/AndroidApp5/MainActivity.cs(15,21): warning CS0168: The variable 'toolbar' is declared but never used [/Users/moljac/Downloads/12063900/AndroidApp5/AndroidApp5.csproj]
AndroidApp5 -> /Users/moljac/Downloads/12063900/AndroidApp5/bin/Debug/net7.0-android/AndroidApp5.dll
Build succeeded.
/Users/moljac/Downloads/12063900/AndroidApp5/MainActivity.cs(15,21): warning CS0168: The variable 'toolbar' is declared but never used [/Users/moljac/Downloads/12063900/AndroidApp5/AndroidApp5.csproj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:00:53.47
I have replicated the issue. There is a bug in the AndroidJavaSource support. It will work with basic java types, however it does have a problem when you try to reference .jar files which are extracted from NuGet packages.
In this case the androidx.appcompat has a classes.jar file, but it is inside an .aar file. This .aar file is extracted to the obj\Debug\net7.0-android\lp\ directory but these directories are NOT included in the list of file needed to compile the code in your .java file.
We will need to update our build system to include these files.
@opcodewriter Its not fixed anywhere at this time. I'll need to figure out what needs to get fixed first.
It might make the final .net 8 release. I'm not sure if it will get ported back to .net 7.
Activity
moljac commentedon Jul 16, 2023
MacOSX
net8.0output:
msbuild.binlog.zip
dellis1972 commentedon Jul 17, 2023
Thanks for the repo app.
I have replicated the issue. There is a bug in the
AndroidJavaSourcesupport. It will work with basic java types, however it does have a problem when you try to reference .jar files which are extracted from NuGet packages.In this case the androidx.appcompat has a classes.jar file, but it is inside an .aar file. This .aar file is extracted to the
obj\Debug\net7.0-android\lp\directory but these directories are NOT included in the list of file needed to compile the code in your .java file.We will need to update our build system to include these files.
opcodewriter commentedon Jul 17, 2023
@dellis1972 Thank you. Any timeline for the fix? Will it be fixed in .NET 7? Or is it already fixed in .NET 8?
I need this to work in .NET 7...
Any workaround at the moment?
dellis1972 commentedon Jul 17, 2023
@opcodewriter Its not fixed anywhere at this time. I'll need to figure out what needs to get fixed first.
It might make the final .net 8 release. I'm not sure if it will get ported back to .net 7.
I'll try adn figure out a work around for you
dellis1972 commentedon Jul 17, 2023
@opcodewriter
ok try adding this to your .csproj just above the final
</Project>element.See if that fixes the issue.
opcodewriter commentedon Jul 17, 2023
In the actual sample app, there's no more compilation error, but when I try to use it in some actual code, I get this error and many warnings:
moljac commentedon Jul 17, 2023
@opcodewriter
Try adding
Xamarin.AndroidX.Annotation.Jvmpackage reference:https://www.nuget.org/packages/Xamarin.AndroidX.Annotation.Jvm
dotnet/android-libraries#727
opcodewriter commentedon Jul 17, 2023
same error and warnings. Note my actual code is in a Android .NET 7 library, not an app like in my sample, not sure if it matters.
[Xamarin.Android.Build.Tasks] Unable to use import androidx.appcompat…
[Xamarin.Android.Build.Tasks] Unable to use import androidx.appcompat…
[Xamarin.Android.Build.Tasks] Unable to use import androidx.appcompat…
[Xamarin.Android.Build.Tasks] Unable to use import androidx.appcompat…
[Xamarin.Android.Build.Tasks] Unable to use import androidx.appcompat…
[Xamarin.Android.Build.Tasks] AndroidJavaSource refs dependent jars (#…
opcodewriter commentedon Oct 4, 2023
Is this going to be released in .NET 8?
Thanks.