Apple.Core appends a second CODE_SIGN_ENTITLEMENTS value instead of reusing the existing entitlements file

Aperta
#131 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
build-system

Direzione di ricerca

Start in AppleBuild.OnPostProcessBuild and trace how the project reads and writes CODE_SIGN_ENTITLEMENTS for iOS, tvOS, and visionOS. Reproduce with the notification package setup described in the issue, then check that Apple.Core uses one entitlements file per target and that Xcode builds successfully.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug Plugin-in - Core

Describe the bug
On iOS and tvOS builds, AppleBuild.OnPostProcessBuild always writes its entitlements to <Product Name>.entitlements and adds that name to CODE_SIGN_ENTITLEMENTS with PBXProject.AddBuildProperty. It never checks what CODE_SIGN_ENTITLEMENTS already points to.

Unity's notification packages (com.unity.services.push-notifications, com.unity.mobile.notifications) run before Apple.Core's [PostProcessBuild(10)]. They read CODE_SIGN_ENTITLEMENTS first and, when it's empty, name the file after the last part of the bundle identifier. So whenever Product Name differs from that part, the project gets two entitlements files and CODE_SIGN_ENTITLEMENTS holds both names. Xcode then fails with an error naming a single file made of both names, for example ExampleGame.entitlements Example Game.entitlements.

The same happens without those packages when building into an existing Xcode project (Append) after changing Product Name: the old name stays and the new one is added next to it.

To Reproduce

  1. iOS project with Apple.Core and com.unity.services.push-notifications (or com.unity.mobile.notifications with push enabled).
  2. Product Name "Example Game", bundle identifier com.example.ExampleGame.
  3. Build for iOS into an empty folder, then build the generated Xcode project.

Expected behavior
One entitlements file per target. If CODE_SIGN_ENTITLEMENTS is already set, Apple.Core should merge its keys into that file, create a file only when none is set, and use SetBuildProperty so the setting never holds two values.

Environment
Unity 6000.6, iOS (tvOS and visionOS go through the same code). Seen with Apple.Core 3.2.0; the code is unchanged in 3.3.0 (27.0, ffe6174) and on main (96e4a04).

Additional context
Sketch of the fix in OnPostProcessBuild:

var targetGuid = pbxProject.GetUnityMainTargetGuid();
var entitlementsFileName = pbxProject.GetBuildPropertyForAnyConfig(targetGuid, "CODE_SIGN_ENTITLEMENTS");
if (string.IsNullOrEmpty(entitlementsFileName))
{
    var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(NamedBuildTarget.FromBuildTargetGroup(BuildPipeline.GetBuildTargetGroup(buildTarget)));
    entitlementsFileName = $"{bundleIdentifier.Substring(bundleIdentifier.LastIndexOf('.') + 1)}.entitlements";
}
// read, merge and write {generatedProjectPath}/{entitlementsFileName}, then:
pbxProject.SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", entitlementsFileName);

Related: #37 switches the file lookup to GetEntitlementFilePathForTarget but keeps AddBuildProperty with the Product Name path, so the setting still gets a second value. Our embedded copy uses the bundle-identifier name plus SetBuildProperty for iOS, tvOS and visionOS, which fixes it for us.

Lingua principale
C#
Stelle
1k
Fork
257
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apple/unityplugins

Tutte le issue di apple/unityplugins

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.