|
| 1 | +<Project> |
| 2 | + |
| 3 | + <UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Java.Interop.BootstrapTasks.dll" TaskName="Java.Interop.BootstrapTasks.ParseAndroidResources" /> |
| 4 | + |
| 5 | + <PropertyGroup> |
| 6 | + <GeneratorPath>$(UtilityOutputFullPath)generator.dll</GeneratorPath> |
| 7 | + <_JcwOutputDir>app/src/main/java/my/</_JcwOutputDir> |
| 8 | + <_GradleJniLibsDir>app/src/main/jniLibs/arm64-v8a</_GradleJniLibsDir> |
| 9 | + <AndroidNdkDirectory Condition=" '$(AndroidNdkDirectory)' == '' ">$(ANDROID_NDK_HOME)</AndroidNdkDirectory> |
| 10 | + <AndroidSdkDirectory Condition=" '$(AndroidSdkDirectory)' == '' ">$(ANDROID_HOME)</AndroidSdkDirectory> |
| 11 | + </PropertyGroup> |
| 12 | + |
| 13 | + <PropertyGroup> |
| 14 | + <_NdkSysrootAbi Condition=" '$(RuntimeIdentifier)' == 'linux-bionic-arm64' ">aarch64-linux-android</_NdkSysrootAbi> |
| 15 | + <_NdkClangPrefix Condition=" '$(RuntimeIdentifier)' == 'linux-bionic-arm64' ">aarch64-linux-android21-</_NdkClangPrefix> |
| 16 | + <_NdkSysrootAbi Condition=" '$(RuntimeIdentifier)' == 'linux-bionic-x64' ">x86_64-linux-android</_NdkSysrootAbi> |
| 17 | + <_NdkClangPrefix Condition=" '$(RuntimeIdentifier)' == 'linux-bionic-x64' ">x86_64-linux-android21-</_NdkClangPrefix> |
| 18 | + <_NdkPrebuiltAbi Condition=" '$(NETCoreSdkRuntimeIdentifier)' == 'osx-x64' ">darwin-x86_64</_NdkPrebuiltAbi> |
| 19 | + <_NdkSysrootLibDir>$(AndroidNdkDirectory)/toolchains/llvm/prebuilt/$(_NdkPrebuiltAbi)/sysroot/usr/lib/$(_NdkSysrootAbi)</_NdkSysrootLibDir> |
| 20 | + <_NdkBinDir>$(AndroidNdkDirectory)/toolchains/llvm/prebuilt/$(_NdkPrebuiltAbi)/bin</_NdkBinDir> |
| 21 | + </PropertyGroup> |
| 22 | + |
| 23 | + <PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))"> |
| 24 | + <CppCompilerAndLinker>$(_NdkBinDir)/$(_NdkClangPrefix)clang</CppCompilerAndLinker> |
| 25 | + <ObjCopyName>$(_NdkBinDir)/llvm-objcopy</ObjCopyName> |
| 26 | + </PropertyGroup> |
| 27 | + |
| 28 | + <ItemGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))"> |
| 29 | + <LinkerArg Include="-Wl,--undefined-version" /> |
| 30 | + </ItemGroup> |
| 31 | + |
| 32 | + <Target Name="_ValidateEnvironment" |
| 33 | + BeforeTargets="Build"> |
| 34 | + <Error |
| 35 | + Condition=" '$(AndroidNdkDirectory)' == '' Or !Exists($(AndroidNdkDirectory)) " |
| 36 | + Text="Set the %24(AndroidNdkDirectory) MSBuild property or the %24ANDROID_NDK_HOME environment variable to the path of the Android NDK." |
| 37 | + /> |
| 38 | + <Error |
| 39 | + Condition=" !Exists($(_NdkSysrootLibDir))" |
| 40 | + Text="NDK 'sysroot' dir `$(_NdkSysrootLibDir)` does not exist. You're on your own." |
| 41 | + /> |
| 42 | + <Error |
| 43 | + Condition=" '$(AndroidSdkDirectory)' == '' Or !Exists($(AndroidSdkDirectory)) " |
| 44 | + Text="Set the %24(AndroidSdkDirectory) MSBuild property or the %24ANDROID_HOME environment variable to the path of the Android SDK." |
| 45 | + /> |
| 46 | + </Target> |
| 47 | + |
| 48 | + <ItemGroup> |
| 49 | + <_GenerateAndroidBindingInputs Include="$(GeneratorPath)" /> |
| 50 | + <_GenerateAndroidBindingInputs Include="$(MSBuildThisFileFullPath)" /> |
| 51 | + <_GenerateAndroidBindingInputs Include="Transforms\**" /> |
| 52 | + <_GenerateAndroidBindingInputs Include="$(IntermediateOutputPath)mcw\api.xml" /> |
| 53 | + </ItemGroup> |
| 54 | + |
| 55 | + <Target Name="_GenerateAndroidBinding" |
| 56 | + BeforeTargets="CoreCompile" |
| 57 | + Inputs="@(_GenerateAndroidBindingInputs)" |
| 58 | + Outputs="$(IntermediateOutputPath)mcw\Hello-NativeAOTFromAndroid.projitems"> |
| 59 | + <MakeDir Directories="$(IntermediateOutputPath)mcw" /> |
| 60 | + <PropertyGroup> |
| 61 | + <Generator>"$(GeneratorPath)"</Generator> |
| 62 | + <_GenFlags>--public --global</_GenFlags> |
| 63 | + <_Out>-o "$(IntermediateOutputPath)mcw"</_Out> |
| 64 | + <_Codegen>--codegen-target=JavaInterop1</_Codegen> |
| 65 | + <_Fixup>--fixup=Transforms/Metadata.xml</_Fixup> |
| 66 | + <_Enums1>--preserve-enums --enumflags=Transforms/enumflags --enumfields=Transforms/map.csv --enummethods=Transforms/methodmap.csv</_Enums1> |
| 67 | + <_Enums2>--enummetadata=$(IntermediateOutputPath)mcw/enummetadata</_Enums2> |
| 68 | + <_Assembly>"--assembly=$(AssemblyName)"</_Assembly> |
| 69 | + <_TypeMap>--type-map-report=$(IntermediateOutputPath)mcw/type-mapping.txt</_TypeMap> |
| 70 | + <_Api>android.xml</_Api> |
| 71 | + <_Dirs>--enumdir=$(IntermediateOutputPath)mcw</_Dirs> |
| 72 | + <_FullIntermediateOutputPath>$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)'))</_FullIntermediateOutputPath> |
| 73 | + <_LangFeatures>--lang-features=nullable-reference-types,default-interface-methods,nested-interface-types,interface-constants</_LangFeatures> |
| 74 | + </PropertyGroup> |
| 75 | + <ItemGroup> |
| 76 | + <_RefAsmDir Include="@(ReferencePathWithRefAssemblies->'%(RootDir)%(Directory).'->Distinct())" /> |
| 77 | + <_Lib Include="@(_RefAsmDir->'-L "%(Identity)"')" /> |
| 78 | + <_JavaBaseRef Include="@(ReferencePathWithRefAssemblies)" |
| 79 | + Condition=" '%(FileName)' == 'Java.Base' " |
| 80 | + /> |
| 81 | + <_Ref Include="@(_JavaBaseRef->'-r "%(FullPath)"')" /> |
| 82 | + </ItemGroup> |
| 83 | + <ItemGroup> |
| 84 | + <!-- I can't find a good way to trim the trailing `\`, so append with `.` so we can sanely quote for $(_Libpath) --> |
| 85 | + </ItemGroup> |
| 86 | + <Exec |
| 87 | + Command="$(DotnetToolPath) $(Generator) $(_GenFlags) $(_ApiLevel) $(_Out) @(_Lib, ' ') @(_Ref, ' ') $(_Codegen) $(_Fixup) $(_Enums1) $(_Enums2) $(_Versions) $(_Annotations) $(_Assembly) $(_TypeMap) $(_LangFeatures) $(_Dirs) $(_Api) $(_WithJavadocXml)" |
| 88 | + IgnoreStandardErrorWarningFormat="True" |
| 89 | + /> |
| 90 | + <ItemGroup> |
| 91 | + <Compile Include="$(_FullIntermediateOutputPath)\mcw\**\*.cs" KeepDuplicates="False" /> |
| 92 | + </ItemGroup> |
| 93 | + <XmlPeek |
| 94 | + Namespaces="<Namespace Prefix='msbuild' Uri='http://schemas.microsoft.com/developer/msbuild/2003' />" |
| 95 | + XmlInputPath="$(IntermediateOutputPath)mcw\Hello-NativeAOTFromAndroid.projitems" |
| 96 | + Query="/msbuild:Project/msbuild:PropertyGroup/msbuild:DefineConstants/text()" > |
| 97 | + <Output TaskParameter="Result" PropertyName="_GeneratedDefineConstants" /> |
| 98 | + </XmlPeek> |
| 99 | + <PropertyGroup> |
| 100 | + <DefineConstants>$(DefineConstants);$([System.String]::Copy('$(_GeneratedDefineConstants)').Replace ('%24(DefineConstants);', ''))</DefineConstants> |
| 101 | + </PropertyGroup> |
| 102 | + </Target> |
| 103 | + |
| 104 | + <Target Name="_CreateJavaCallableWrappers" |
| 105 | + Condition=" '$(TargetPath)' != '' " |
| 106 | + BeforeTargets="_BuildAppApk" |
| 107 | + Inputs="$(TargetPath)" |
| 108 | + Outputs="$(_JcwOutputDir).stamp"> |
| 109 | + <RemoveDir Directories="$(_JcwOutputDir)" /> |
| 110 | + <MakeDir Directories="$(_JcwOutputDir)" /> |
| 111 | + <ItemGroup> |
| 112 | + <!-- I can't find a good way to trim the trailing `\`, so append with `.` so we can sanely quote for $(_Libpath) --> |
| 113 | + <_JcwGenRefAsmDirs Include="@(ReferencePathWithRefAssemblies->'%(RootDir)%(Directory).'->Distinct())" /> |
| 114 | + </ItemGroup> |
| 115 | + <PropertyGroup> |
| 116 | + <_JcwGen>"$(UtilityOutputFullPath)/jcw-gen.dll"</_JcwGen> |
| 117 | + <_Target>--codegen-target JavaInterop1</_Target> |
| 118 | + <_Output>-o "$(_JcwOutputDir)"</_Output> |
| 119 | + <_Libpath>@(_JcwGenRefAsmDirs->'-L "%(Identity)"', ' ')</_Libpath> |
| 120 | + </PropertyGroup> |
| 121 | + <Exec Command="$(DotnetToolPath) $(_JcwGen) "$(TargetPath)" $(_Target) $(_Output) $(_Libpath)" /> |
| 122 | + <Touch Files="$(_JcwOutputDir).stamp" AlwaysCreate="True" /> |
| 123 | + </Target> |
| 124 | + |
| 125 | + <Target Name="_AddMarshalMethods" |
| 126 | + Condition=" '$(TargetPath)' != '' " |
| 127 | + Inputs="$(TargetPath)" |
| 128 | + Outputs="$(IntermediateOutputPath).added-marshal-methods" |
| 129 | + AfterTargets="_CreateJavaCallableWrappers"> |
| 130 | + <ItemGroup> |
| 131 | + <!-- I can't find a good way to trim the trailing `\`, so append with `.` so we can sanely quote for $(_Libpath) --> |
| 132 | + <_JnimmRefAsmDirs Include="@(RuntimePackAsset->'%(RootDir)%(Directory).'->Distinct())" /> |
| 133 | + </ItemGroup> |
| 134 | + <PropertyGroup> |
| 135 | + <_JnimarshalmethodGen>"$(UtilityOutputFullPath)/jnimarshalmethod-gen.dll"</_JnimarshalmethodGen> |
| 136 | + <_Verbosity>-v -v --keeptemp</_Verbosity> |
| 137 | + <_Libpath>-L "$(TargetDir)" @(_JnimmRefAsmDirs->'-L "%(Identity)"', ' ')</_Libpath> |
| 138 | + <!-- <_Output>-o "$(IntermediateOutputPath)/jonp"</_Output> --> |
| 139 | + </PropertyGroup> |
| 140 | + |
| 141 | + <Exec Command="$(DotnetToolPath) $(_JnimarshalmethodGen) "$(TargetPath)" $(_Verbosity) $(_Libpath)" /> |
| 142 | + |
| 143 | + <!-- the IlcCompile target uses files from `$(IntermediateOutputPath)`, not `$(TargetPath)`, so… update both? --> |
| 144 | + <Copy SourceFiles="$(TargetPath)" DestinationFolder="$(IntermediateOutputPath)" /> |
| 145 | + |
| 146 | + <Touch Files="$(IntermediateOutputPath).added-marshal-methods" AlwaysCreate="True" /> |
| 147 | + </Target> |
| 148 | + |
| 149 | + <ItemGroup> |
| 150 | + <_BuildAppApkInput Include="$(MSBuildThisFileFullPath)" /> |
| 151 | + <_BuildAppApkInput Include="app\src\main\java\**\*.java" /> |
| 152 | + <_BuildAppApkInput Include="app\src\main\AndroidManifest.xml" /> |
| 153 | + <_BuildAppApkInput Include="app\**\build.gradle" /> |
| 154 | + <_BuildAppApkInput Include="$(NativeBinary)" /> |
| 155 | + <_BuildAppApkInput Include="$(OutputPath)java-interop.jar" /> |
| 156 | + </ItemGroup> |
| 157 | + |
| 158 | + <PropertyGroup> |
| 159 | + <_AfterBuildDependsOnTargets> |
| 160 | + _CreateJavaCallableWrappers; |
| 161 | + _AddMarshalMethods; |
| 162 | + </_AfterBuildDependsOnTargets> |
| 163 | + </PropertyGroup> |
| 164 | + |
| 165 | + <Target Name="_AfterBuild" |
| 166 | + AfterTargets="Build" |
| 167 | + DependsOnTargets="$(_AfterBuildDependsOnTargets)" |
| 168 | + /> |
| 169 | + |
| 170 | + <PropertyGroup> |
| 171 | + <_GradleRtxtPath>app\build\intermediates\runtime_symbol_list\release\R.txt</_GradleRtxtPath> |
| 172 | + </PropertyGroup> |
| 173 | + |
| 174 | + <Target Name="_BuildRtxt" |
| 175 | + BeforeTargets="CoreCompile" |
| 176 | + Inputs="@(_BuildAppApkInput)" |
| 177 | + Outputs="$(_GradleRtxtPath);$(IntermediateOutputPath)R.g.cs"> |
| 178 | + <Exec |
| 179 | + Command=""$(GradleWPath)" $(GradleArgs) :app:processReleaseResources" |
| 180 | + EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome);ANDROID_HOME=$(AndroidSdkDirectory)" |
| 181 | + WorkingDirectory="$(MSBuildThisFileDirectory)" |
| 182 | + /> |
| 183 | + <ParseAndroidResources |
| 184 | + AndroidResourceFile="$(_GradleRtxtPath)" |
| 185 | + OutputFile="$(IntermediateOutputPath)R.g.cs" |
| 186 | + DeclaringNamespaceName="$(RootNamespace)" |
| 187 | + DeclaringClassName="R" |
| 188 | + /> |
| 189 | + <ItemGroup> |
| 190 | + <FileWrites Include="$(IntermediateOutputPath)R.g.cs" /> |
| 191 | + <Compile Include="$(IntermediateOutputPath)R.g.cs" /> |
| 192 | + </ItemGroup> |
| 193 | + </Target> |
| 194 | + |
| 195 | + <Target Name="_BuildAppApk" |
| 196 | + AfterTargets="Publish" |
| 197 | + Inputs="@(_BuildAppApkInput)" |
| 198 | + Outputs="app/build/outputs/apk/release/app-release.apk"> |
| 199 | + <MakeDir Directories="$(_GradleJniLibsDir);app/lib" /> |
| 200 | + <ItemGroup> |
| 201 | + <_GradleBuildSource Include="$(NativeBinary)" /> |
| 202 | + <_GradleBuildTarget Include="$(_GradleJniLibsDir)\lib$(AssemblyName)$(NativeBinaryExt)" /> |
| 203 | + |
| 204 | + <_GradleBuildSource Include="$(OutputPath)java-interop.jar" /> |
| 205 | + <_GradleBuildTarget Include="app\lib\java-interop.jar" /> |
| 206 | + </ItemGroup> |
| 207 | + <Copy |
| 208 | + SourceFiles="@(_GradleBuildSource)" |
| 209 | + DestinationFiles="@(_GradleBuildTarget)" |
| 210 | + /> |
| 211 | + <Exec |
| 212 | + Command=""$(GradleWPath)" $(GradleArgs) assembleRelease > gradle.log" |
| 213 | + EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome);ANDROID_HOME=$(AndroidSdkDirectory)" |
| 214 | + WorkingDirectory="$(MSBuildThisFileDirectory)" |
| 215 | + /> |
| 216 | + <Copy |
| 217 | + SourceFiles="app/build/outputs/apk/release/app-release.apk" |
| 218 | + DestinationFiles="$(OutputPath)net.dot.jni.helloandroid-Signed.apk" |
| 219 | + /> |
| 220 | + </Target> |
| 221 | +</Project> |
0 commit comments